diff --git a/src/program.c b/src/program.c
index f249213a435fec4d4fa3367840dcc0ae96896d1d..8569a858ffc1331ff198e2d392dc0a56d011292a 100644
--- a/src/program.c
+++ b/src/program.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: program.c,v 1.97 1998/07/17 13:31:22 grubba Exp $");
+RCSID("$Id: program.c,v 1.98 1998/07/17 22:37:10 hubbe Exp $");
 #include "program.h"
 #include "object.h"
 #include "dynamic_buffer.h"
@@ -2683,7 +2683,12 @@ static struct find_child_cache_s find_child_cache[FIND_CHILD_HASHSIZE];
 
 int find_child(struct program *parent, struct program *child)
 {
-  INT32 h=(parent->id  * 9248339 + child->id) % FIND_CHILD_HASHSIZE;
+  unsigned INT32 h=(parent->id  * 9248339 + child->id);
+  h= h % FIND_CHILD_HASHSIZE;
+#ifdef DEBUG
+  if(h>=FIND_CHILD_HASHSIZE)
+    fatal("find_child failed to hash within boundaries.\n");
+#endif  
   if(find_child_cache[h].pid == parent->id &&
      find_child_cache[h].cid == child->id)
   {
@@ -2761,6 +2766,10 @@ int implements(struct program *a, struct program *b)
 
   hval = a->id*9248339 + b->id;
   hval %= IMPLEMENTS_CACHE_SIZE;
+#ifdef DEBUG
+  if(hval >= IMPLEMENTS_CACHE_SIZE)
+    fatal("Implements_cache failed!\n");
+#endif
   if(implements_cache[hval].aid==a->id && implements_cache[hval].bid==b->id)
   {
     return implements_cache[hval].ret;
diff --git a/src/threads.c b/src/threads.c
index 3e41bee78c8aa3a069831426bb9a7404d51acc9d..f581827bd1f0d90adb4442901dbce9916fd4327d 100644
--- a/src/threads.c
+++ b/src/threads.c
@@ -1,5 +1,5 @@
 #include "global.h"
-RCSID("$Id: threads.c,v 1.78 1998/07/17 13:28:25 grubba Exp $");
+RCSID("$Id: threads.c,v 1.79 1998/07/17 22:37:11 hubbe Exp $");
 
 int num_threads = 1;
 int threads_disabled = 0;
@@ -326,6 +326,10 @@ void thread_table_insert(struct object *o)
 {
   struct thread_state *s = (struct thread_state *)o->storage;
   unsigned INT32 h = thread_table_hash(&s->id);
+#ifdef DEBUG
+  if(h>=THREAD_TABLE_SIZE)
+    fatal("thread_table_hash failed miserably!\n");
+#endif
   mt_lock( & thread_table_lock );
   if((s->hashlink = thread_table_chains[h]) != NULL)
     s->hashlink->backlink = &s->hashlink;
@@ -348,6 +352,10 @@ struct thread_state *thread_state_for_id(THREAD_T tid)
 {
   unsigned INT32 h = thread_table_hash(&tid);
   struct thread_state *s = NULL;
+#ifdef DEBUG
+  if(h>=THREAD_TABLE_SIZE)
+    fatal("thread_table_hash failed miserably!\n");
+#endif
   mt_lock( & thread_table_lock );
   if(thread_table_chains[h] == NULL)
   {