diff -ruN klic-3.003-2002-01-11/runtime/gg_shbusy.c klic-3.003-2002-01-12/runtime/gg_shbusy.c
--- klic-3.003-2002-01-11/runtime/gg_shbusy.c	Sat Dec 29 12:46:20 2001
+++ klic-3.003-2002-01-12/runtime/gg_shbusy.c	Sat Jan 12 13:23:24 2002
@@ -20,43 +20,42 @@
 #define GG_CLASS_NAME() shbusy
 #define GG_OBJ_TYPE struct Shbusy
 
+#define One_more  do_unify(g_allocp, GG_SELF, GG_TERM)
+
 struct Shbusy {
   struct generator_object_method_table *method_table;
 };
 
-extern struct generator_object* pSHM_BUSY;
 extern q* do_unify();
 
-#define One_more do_unify(g_allocp,GG_SELF,GG_TERM)
-
 GGDEF_UNIFY()
 {
   G_STD_DECL;
 
   struct generator_object* gobj;
   q pair = derefone(GG_SELF);
-  if ( !isref(pair) || GG_SELF != derefone(pair) ) { return One_more;}
-  gobj = n_lock(GG_SELF,pair);
-  if ( derefone(GG_SELF) == pair ) {
-    n_unlock(pair,gobj);
+  if( !isref(pair) || GG_SELF != derefone(pair) ){ return One_more; }
+  gobj = n_lock(GG_SELF, pair);
+  if( derefone(GG_SELF) == pair ){
+    n_unlock(pair, gobj);
   }
   return One_more;
 }
 
 GGDEF_GENERATE()
 {
-   return( makecons(0) );
+  return makecons(0);
 }
 
 GGDEF_SUSPEND()
 {
-  return( makecons(0) );
+  return makecons(0);
 }
 
 GGDEF_PRINT()
 {
   fprintf(g_fp, "<BUSY Generator %x>", GG_SELF);
-  return(0);
+  return 0;
 }
 
 GGDEF_GC()
diff -ruN klic-3.003-2002-01-11/runtime/gg_shvar.c klic-3.003-2002-01-12/runtime/gg_shvar.c
--- klic-3.003-2002-01-11/runtime/gg_shvar.c	Wed Jan  2 14:44:16 2002
+++ klic-3.003-2002-01-12/runtime/gg_shvar.c	Sat Jan 12 13:20:15 2002
@@ -15,48 +15,45 @@
 #include "gobj.h"
 #include "shm.h"
 
-#define GENHOOK
-#define GENHOPT
+#define GENHOOK  1
+#define GENHOPT  1
 
 #define GG_CLASS_NAME() shvar
 #define GG_OBJ_TYPE struct Shvar
 
-#define cmp_forward_ptr(x,y) ( {\
-    int xv;                 \
-    int yv;                 \
-    int ret;                \
-    xv = get_space(x);      \
-    yv = get_space(y);      \
-    if ( xv == yv ) {       \
-      if ((x) < (y)) ret = 1; \
-      else         ret = 0; \
-    } else if ( xv < yv ) { \
-       ret = 1;             \
-    } else {                \
-       ret = 0;             \
-    }                       \
-    ret;} )
-
-#define is_forward_space_ptr(X) ( {\
-    int ok = 0;\
-    int cid = currid;\
-    while ( (cid = PLNE_ptr[cid]->direct) != (-1) ) {\
-       if ( (unsigned long)((long)(X)-(long)(PLNE_ptr[cid]->top_addr) ) < SHM_SIZE ) {\
-	 ok = 1; break;\
-       }\
-    }\
-    ok; } )
+#define One_more  do_unify(g_allocp, GG_SELF, GG_TERM)
 
-typedef struct Shvar {
+struct Shvar {
   struct generator_object_method_table *method_table;
   Sinfo chain;
-} Shm_var;
+};
 
-Sinfo* shm_copy_chain();
-Sinfo* shm_merge_chain();
+extern Sinfo* shm_copy_chain();
+extern Sinfo* shm_merge_chain();
 
-q* do_unify();
-#define One_more do_unify(g_allocp,GG_SELF,GG_TERM)
+extern q* do_unify();
+
+static Inline int
+cmp_forward_ptr(q x, q y)
+{
+  int xv = get_space(x);
+  int yv = get_space(y);
+  return (xv==yv) ? (x < y) : (xv < yv);
+}
+
+static Inline int
+is_forward_space_ptr(Sinfo* gp)
+{
+  int ok = 0;
+  int cid;
+  while( (cid = PLNE_ptr[cid]->direct) != -1 ){
+    if( (unsigned long)((long)gp-(long)(PLNE_ptr[cid]->top_addr)) < SHM_SIZE ){
+      ok = 1;
+      break;
+    }
+  }
+  return ok;
+}
 
 GGDEF_UNIFY()
 {
@@ -65,258 +62,265 @@
   struct generator_object *addi;
   Shvar *gobjp;
   q pair = derefone(GG_SELF);
-  if ( !isref(pair) || GG_SELF != derefone(pair) )   return One_more;
-  addi = n_lock(GG_SELF,pair);
-  if ( pair != derefone(GG_SELF) )  return One_more;
-
-  gobjp = (Shvar*)untag_generator_susp(addi);
-  GG_SWITCH_ON_TERM(cons,atomic,func,dobj,susp)
- atomic: {
-  derefone(GG_SELF) = GG_TERM;
-  if ( gobjp->chain ) {
-    if ( is_genhook(gobjp->chain) ) {
-      g_allocp = shm_ck_request(g_allocp,gobjp->chain);
-    } else {
-      g_allocp = shm_resume_goals(g_allocp,gobjp->chain);
+  if( !isref(pair) || GG_SELF != derefone(pair) )  return One_more;
+  addi = n_lock(GG_SELF, pair);
+  if( pair != derefone(GG_SELF) )  return One_more;
+
+  gobjp = (Shvar*) untag_generator_susp(addi);
+  GG_SWITCH_ON_TERM(cons, atomic, func, dobj, susp)
+
+ atomic:
+  {
+    derefone(GG_SELF) = GG_TERM;
+    if( gobjp->chain ){
+      if( is_genhook(gobjp->chain) ){
+	g_allocp = shm_ck_request(g_allocp, gobjp->chain);
+      }else{
+	g_allocp = shm_resume_goals(g_allocp, gobjp->chain);
+      }
     }
+    GG_RETURN;
   }
-  GG_RETURN;
- }
+
  cons:
  func:
- dobj: {
-  q y;
-#ifdef GENHOOK
-  if ( !gobjp->chain && !is_shma(GG_TERM)
-#ifdef GENHOPT
-  && last_shm_var == GG_SELF
-#endif
-                       ) {
-    gobjp = create_genhook(GG_TERM,GG_SELF);
-    n_unlock(pair,tag_generator_susp(gobjp));
-    GG_RETURN;
-  } else {
-#endif
-    ck_new_galloc(GG_SELF);
-    y = shm_copy(GG_TERM);
-    klic_barrier();
-    derefone(GG_SELF) = y;
-    if ( gobjp->chain ) {
-      if ( is_genhook(gobjp->chain) ) {
-        g_allocp = shm_ck_request(g_allocp,gobjp->chain);
-      } else {
-        g_allocp = shm_resume_goals(g_allocp,gobjp->chain);
+ dobj:
+  {
+    q y;
+    if( GENHOOK && !gobjp->chain && !is_shma(GG_TERM)
+	&& (!GENHOPT || last_shm_var == GG_SELF) ){
+      gobjp = create_genhook(GG_TERM, GG_SELF);
+      n_unlock(pair, tag_generator_susp(gobjp));
+      GG_RETURN;
+    }else{
+      ck_new_galloc(GG_SELF);
+      y = shm_copy(GG_TERM);
+      klic_barrier();
+      derefone(GG_SELF) = y;
+      if( gobjp->chain ){
+	if( is_genhook(gobjp->chain) ){
+	  g_allocp = shm_ck_request(g_allocp, gobjp->chain);
+	}else{
+	  g_allocp = shm_resume_goals(g_allocp, gobjp->chain);
+	}
       }
     }
-#ifdef GENHOOK
+    GG_RETURN;
   }
-#endif
-  GG_RETURN;
- }
-
- susp: {
-  q x = GG_SELF;
-  q temp = pair;
-  struct generator_object* xaddi = addi;
-  Shvar* xobjp = gobjp;
-  q y = GG_TERM;
-  q ytemp;
-  struct generator_object* yaddi;
-  Shvar* yobjp;
-
- Re_try:
-
-  ytemp = derefone(y);
-  if ( !isref(ytemp) )        { n_unlock(temp,xaddi); return One_more;}
-  if ( y != derefone(ytemp) ) { n_unlock(temp,xaddi); return One_more;}
-  yaddi = generator_suspp(ytemp)->u.o;
-/*  if ( is_generator_susp(yaddi) ) { */
-  if ( (long)yaddi & 0x1 ) {
-    struct generator_object_method_table* m;
-    yobjp = (Shvar*)untag_generator_susp(yaddi);
-    m = yobjp->method;
-    if (m == SHM_VAR || m == SHM_BUSY) {
-      if ( x == y )           { n_unlock(temp,xaddi); GG_RETURN;}
-      if ( cmp_forward_ptr(x,y) ) { /* reverse order */
-        q w;
-        n_unlock(temp,xaddi);
-        w = x; x = y; y = w;
-        w = temp; temp = ytemp; ytemp = w;
-	xaddi = n_lock(x,temp);
-        if ( temp != derefone(x) )  { return One_more;}
-        xobjp = (Shvar*)untag_generator_susp(xaddi);
-      }
 
-      if ( xobjp->chain ) {
-        if ( is_genhook(xobjp->chain) ) { /* one is a generator hook. */
-	  derefone(x) = y;
-	  g_allocp = shm_ck_request(g_allocp,xobjp->chain);
-        } else {              /* one is a normal hook */
-	  yaddi = n_lock(y,ytemp);
-	  if ( derefone(y) != ytemp )  { n_unlock(temp,xaddi); return One_more;}
-	  yobjp = (Shvar*)untag_generator_susp(yaddi);
-	  if ( yobjp->chain ) {
-	    if ( is_genhook(yobjp->chain) ) { /* another is a generator hook. */
-	      Sinfo* ychain = yobjp->chain;
-	      ck_new_galloc(yobjp);
-	      /* Don't forget keeping direction */
-	      yobjp->chain = shm_copy_chain(xobjp->chain); 
-	      n_unlock(ytemp,yaddi);
-	      derefone(x) = y;
-	      g_allocp = shm_ck_request(g_allocp,ychain);
-	    } else { /* both are ordinary hooks */
-	      ck_new_galloc(yobjp);
-	      yobjp->chain = shm_merge_chain(xobjp->chain,yobjp->chain);
-	      n_unlock(ytemp,yaddi);
-	      derefone(x) = y;
+ susp:
+  {
+    q x = GG_SELF;
+    q temp = pair;
+    struct generator_object* xaddi = addi;
+    Shvar* xobjp = gobjp;
+    q y = GG_TERM;
+    q ytemp;
+    struct generator_object* yaddi;
+    Shvar* yobjp;
+
+  Re_try:
+    ytemp = derefone(y);
+    if( !isref(ytemp) ){
+      n_unlock(temp, xaddi);
+      return One_more;
+    }
+    if( y != derefone(ytemp) ){
+      n_unlock(temp, xaddi);
+      return One_more;
+    }
+    yaddi = generator_suspp(ytemp)->u.o;
+    /* if yaddi is generator_susp */
+    if( (long)yaddi & 1L ){
+      struct generator_object_method_table* m;
+      yobjp = (Shvar*) untag_generator_susp(yaddi);
+      m = yobjp->method;
+      if( m == SHM_VAR || m == SHM_BUSY ){
+	if( x == y ){
+	  n_unlock(temp, xaddi);
+	  GG_RETURN;
+	}
+	if( cmp_forward_ptr(x,y) ){ /* reverse order */
+	  q w;
+	  n_unlock(temp, xaddi);
+	  w = x; x = y; y = w;
+	  w = temp; temp = ytemp; ytemp = w;
+	  xaddi = n_lock(x, temp);
+	  if( temp != derefone(x) ){
+	    return One_more;
+	  }
+	  xobjp = (Shvar*) untag_generator_susp(xaddi);
+	}
+
+	if( xobjp->chain ){
+	  if( is_genhook(xobjp->chain) ){ /* one is a generator hook. */
+	    derefone(x) = y;
+	    g_allocp = shm_ck_request(g_allocp, xobjp->chain);
+	  }else{              /* one is a normal hook */
+	    yaddi = n_lock(y, ytemp);
+	    if( derefone(y) != ytemp ){
+	      n_unlock(temp,xaddi);
+	      return One_more;
 	    }
-	  } else {
-	    ck_new_galloc(y);
-	    if ( is_cur_or_forward_ptr(xobjp) ) {
-	      n_unlock(ytemp,tag_generator_susp(xobjp));
-	      derefone(x) = y;
-	    } else {
-	      yobjp = (Shvar*)galloc(sizeof(Shvar)/sizeof(q));
-	      yobjp->method = SHM_VAR;
-	      yobjp->chain = shm_copy_chain(xobjp->chain);
-	      n_unlock(ytemp,tag_generator_susp(yobjp));
-	      derefone(x) = y;
+	    yobjp = (Shvar*) untag_generator_susp(yaddi);
+	    if( yobjp->chain ){
+	      if( is_genhook(yobjp->chain) ){ /* another is a generator hook. */
+		Sinfo* ychain = yobjp->chain;
+		ck_new_galloc(yobjp);
+		/* Don't forget keeping direction */
+		yobjp->chain = shm_copy_chain(xobjp->chain);
+		n_unlock(ytemp, yaddi);
+		derefone(x) = y;
+		g_allocp = shm_ck_request(g_allocp, ychain);
+	      }else{ /* both are ordinary hooks */
+		ck_new_galloc(yobjp);
+		yobjp->chain = shm_merge_chain(xobjp->chain, yobjp->chain);
+		n_unlock(ytemp, yaddi);
+		derefone(x) = y;
+	      }
+	    }else{
+	      ck_new_galloc(y);
+	      if( is_cur_or_forward_ptr(xobjp) ){
+		n_unlock(ytemp, tag_generator_susp(xobjp));
+		derefone(x) = y;
+	      }else{
+		yobjp = (Shvar*) galloc(sizeof(Shvar)/sizeof(q));
+		yobjp->method = SHM_VAR;
+		yobjp->chain = shm_copy_chain(xobjp->chain);
+		n_unlock(ytemp, tag_generator_susp(yobjp));
+		derefone(x) = y;
+	      }
 	    }
 	  }
-        }
-      } else { /* x has no additional info. */
-        derefone(x) = y;
+	}else{ /* x has no additional info. */
+	  derefone(x) = y;
+	}
+      }else{ /* y is an other local generator object */
+	/* assumes user defined object. Not Exref */
+	if( xobjp->chain ){ /* x has any info */
+	  struct generator_object* gobjy = untag_generator_susp(yaddi);
+	  q tmpy = generic_generate(gobjy, g_allocp);
+	  switch( (long)tmpy ){
+	  case (long) makeref(0):
+	    GG_KL1_UNIFY(x, y);
+	    GG_RETURN;
+	  case (long) makecons(0):
+	    fatal("system bug!!!");
+	  default:
+	    g_allocp = heapp;
+	    derefone(y) = tmpy;
+	    return One_more;
+	  }
+	}else{ /* x is a simple variable */
+	  xobjp = create_genhook(tag_local(y), x);
+	  n_unlock(temp, tag_generator_susp(xobjp));
+	}
       }
-    } else { /* y is an other local generator object */
-      /* assumes user defined object. Not Exref */
-      if ( xobjp->chain ) { /* x has any info */
-        struct generator_object *gobjy = untag_generator_susp(yaddi);
-        q tmpy = generic_generate(gobjy,g_allocp);
-        switch((long)tmpy) {
-        case (long)makeref(0):
-          GG_KL1_UNIFY(x,y);
-          GG_RETURN;
-        case (long)makecons(0):
-          fatal("system bug!!!");
-        default:
-          g_allocp = heapp;
-          derefone(y) = tmpy;
-          return One_more;
-        }
-      } else { /* x is a simple variable */
-        xobjp = create_genhook(tag_local(y),x);
-        n_unlock(temp,tag_generator_susp(xobjp));
+    }else{ /* y is a consumer */
+      if( xobjp && is_genhook(xobjp->chain) ){ /* global generator hook */
+	Shvar* tobj = shm_add_consumer(x, 0, y, glbl);
+	g_allocp = shm_ck_request(g_allocp, xobjp->chain);
+	n_unlock(temp, tag_generator_susp(tobj));
+      }else{
+	Shvar* tobj = (Shvar*) shm_add_consumer(x, xobjp, y, glbl);
+	n_unlock(temp, tag_generator_susp(tobj));
       }
     }
-  } else { /* y is a consumer */
-    if ( xobjp && is_genhook(xobjp->chain) ) { /* global generator hook */
-      Shvar* tobj = shm_add_consumer(x,0,y,glbl);
-      g_allocp = shm_ck_request(g_allocp,xobjp->chain);
-      n_unlock(temp,tag_generator_susp(tobj));
-    } else {
-      Shvar* tobj = (Shvar*)shm_add_consumer(x,xobjp,y,glbl);
-      n_unlock(temp,tag_generator_susp(tobj));
-    }
-  }
-  GG_RETURN;
+    GG_RETURN;
   }
 }
-/*
-static q
-generate(self, g_allocp)
-struct integer_generator *self;
-q *g_allocp;
-*/
+
 GGDEF_GENERATE()
 {
-  return( makecons(0) );
+  return makecons(0);
 }
 
 GGDEF_SUSPEND()
 {
   G_STD_DECL;
   struct generator_object* addi;
+  Sinfo* sptr;
+  Sinfo* gp;
+  Shvar* gvar;
   q temp = derefone(GG_SELF);
-  if ( !isref(temp) )   return( makecons(0) );
-  if ( GG_SELF != derefone(temp) )  return( makecons(0) );
-  addi = n_lock(GG_SELF,temp);
-  if ( derefone(GG_SELF) != temp )  return( makecons(0) );
+  if( !isref(temp) )  return makecons(0);
+  if( GG_SELF != derefone(temp) )  return makecons(0);
+  addi = n_lock(GG_SELF, temp);
+  if( derefone(GG_SELF) != temp )  return makecons(0);
   ck_new_galloc(GG_SELF);
+
   /* creates shared memory hook chain */
-  {
-    Sinfo* sptr;
-    Shvar* gvar = (Shvar*)untag_generator_susp(addi);
-    Sinfo* gp = gvar->chain;
-    if ( !gp ) { /* First hook */
-      Shvar* gptr = (Shvar*)galloc(
-         (sizeof(Shvar)+sizeof(Sinfo))/sizeof(q) );
-      sptr = (Sinfo*)(gptr+1);
-      gptr->method = SHM_VAR;
-      gptr->chain = sptr;
-      sptr->next = 0;
-      sptr->PE_num = my_node;
-      sptr->prio = current_prio;
-      sptr->indp = create_local_tbl(GG_GOAL,GG_SELF);
-      n_unlock(temp,tag_generator_susp(gptr));
-      return( makeref(0) );
-    }
-    /* already any hooks */
-    if ( is_genhook(gp) ) { /* shared generator hook */
-      Sinfo* sptr = (Sinfo*)untag_generator_susp(gp);
-      int pe_num = sptr->PE_num;
-      long prio = sptr->prio;
-      TADDRtbl* ind = sptr->indp;
-      if ( pe_num == my_node ) {
-	q temp;
-	q* tp = ind->globalA;
-	if ( !isatomic(ind->localA) ) {
-	  free_local_tbl(ind);
-	  shm_arg_copy(&ind->localA,&temp);
-	  klic_barrier();
-	  *tp = temp;
-	  return( makecons(0) );
-	}
+
+  gvar = (Shvar*) untag_generator_susp(addi);
+  gp = gvar->chain;
+  if( gp == NULL ){ /* First hook */
+    Shvar* gptr = (Shvar*) galloc( (sizeof(Shvar)+sizeof(Sinfo))/sizeof(q) );
+    sptr = (Sinfo*) (gptr+1);
+    gptr->method = SHM_VAR;
+    gptr->chain = sptr;
+    sptr->next = NULL;
+    sptr->PE_num = my_node;
+    sptr->prio = current_prio;
+    sptr->indp = create_local_tbl(GG_GOAL, GG_SELF);
+    n_unlock(temp, tag_generator_susp(gptr));
+    return makeref(0);
+  }
+  /* already any hooks */
+  else if( is_genhook(gp) ){ /* shared generator hook */
+    sptr = (Sinfo*) untag_generator_susp(gp);
+    int pe_num = sptr->PE_num;
+    long prio = sptr->prio;
+    TADDRtbl* ind = sptr->indp;
+    if( pe_num == my_node ){
+      q temp;
+      q* tp = ind->globalA;
+      if( !isatomic(ind->localA) ){
+	free_local_tbl(ind);
+	shm_arg_copy(&ind->localA, &temp);
+	klic_barrier();
+	*tp = temp;
+	return makecons(0);
       }
-      /* reuses Sinfo */
-      gvar->method = SHM_VAR;
-      gvar->chain = sptr;
-      sptr->PE_num = my_node;
-      sptr->prio = current_prio;
-      sptr->indp = create_local_tbl(GG_GOAL,GG_SELF);
-      shm_request_queueing(pe_num,prio,ind);
-      n_unlock(temp,addi);
-      return( makeref(0) );
-    } else { /* ordinary hook */
-      Sinfo* bgp = (Sinfo*)&(gvar->chain);
-      ck_new_galloc(gvar);
-      while( gp && !is_forward_space_ptr(gp) ) {
-	if ( gp->PE_num == my_node ) {
-	  if ( (struct goalrec*)(gp->indp->localA) == GG_GOAL ) {
-	    n_unlock(temp,addi);
-	    return( makeref(0) );
-	  } else {
-	    break;
-	  }
+    }
+    /* reuses Sinfo */
+    gvar->method = SHM_VAR;
+    gvar->chain = sptr;
+    sptr->PE_num = my_node;
+    sptr->prio = current_prio;
+    sptr->indp = create_local_tbl(GG_GOAL, GG_SELF);
+    shm_request_queueing(pe_num, prio, ind);
+    n_unlock(temp, addi);
+    return makeref(0);
+  }else{ /* ordinary hook */
+    Sinfo* bgp = (Sinfo*) &(gvar->chain);
+    ck_new_galloc(gvar);
+    while( gp != NULL && !is_forward_space_ptr(gp) ){
+      if( gp->PE_num == my_node ){
+	if( (struct goalrec*)(gp->indp->localA) == GG_GOAL ){
+	  n_unlock(temp, addi);
+	  return makeref(0);
+	}else{
+	  break;
 	}
-	bgp = gp;
-	gp = gp->next;
       }
-      sptr = (Sinfo*)galloc(sizeof(Sinfo)/sizeof(q));
-      bgp->next = sptr;
-      sptr->next = gp;
-      sptr->PE_num = my_node;
-      sptr->prio = current_prio;
-      sptr->indp = create_local_tbl(GG_GOAL,GG_SELF);
-      n_unlock(temp,addi);
-      return( makeref(0) );
+      bgp = gp;
+      gp = gp->next;
     }
+    sptr = (Sinfo*) galloc(sizeof(Sinfo)/sizeof(q));
+    bgp->next = sptr;
+    sptr->next = gp;
+    sptr->PE_num = my_node;
+    sptr->prio = current_prio;
+    sptr->indp = create_local_tbl(GG_GOAL, GG_SELF);
+    n_unlock(temp, addi);
+    return makeref(0);
   }
 }
 
 GGDEF_PRINT()
 {
   fprintf(g_fp, "<INTEGER GENERATOR %x>", GG_SELF);
-  return(0);
+  return 0;
 }
 
 GGDEF_GC()
diff -ruN klic-3.003-2002-01-11/runtime/ggoal.c klic-3.003-2002-01-12/runtime/ggoal.c
--- klic-3.003-2002-01-11/runtime/ggoal.c	Tue Jan  1 14:17:47 2002
+++ klic-3.003-2002-01-12/runtime/ggoal.c	Sat Jan 12 12:04:50 2002
@@ -22,11 +22,16 @@
 #include <klic/g_vector.h>
 #include "trace.h"  /* untrace_goal */
 
-extern struct data_object_method_table
-  predicate_g_data_method_table,
-  vector_g_data_method_table;
+#define HashFunc(pred)	((((unsigned long) (pred)) >> 2) & hash_mask)
 
 extern const struct predicate step_trigger_pred;
+extern const struct modinfo defined_modules[];
+
+extern struct data_object_method_table predicate_g_data_method_table;
+extern struct data_object_method_table vector_g_data_method_table;
+
+extern unsigned long enter_atom_body();
+extern q size_of_vector();
 
 /* Predicate Table */
 
@@ -34,19 +39,17 @@
   const struct predicate* pred;
   q modname;			/* module name atom */
   q name;			/* predicate name atom */
-} *pred_tab;
+};
 
+static struct pred_tab_ent* pred_tab;
 static unsigned long hash_mask;
 
-#define HashFunc(pred)	((((unsigned long) (pred)) >> 2) & hash_mask)
-
-static pred_tab_made = 0;
-static make_pred_tab()
+static void
+make_pred_tab()
 {
   declare_globals;
   int k, n_pred;
   const struct modinfo* dm;
-  extern const struct modinfo defined_modules[];
 
   /* Let's first count the number predicates in this program */
   n_pred = 0;
@@ -62,8 +65,7 @@
     unsigned long hash_size = 1;
     while (hash_size <= (3*n_pred/2)) hash_size *= 2;
     pred_tab =
-      (struct pred_tab_ent *)
-	calloc(hash_size, sizeof(struct pred_tab_ent));
+      (struct pred_tab_ent*) calloc(hash_size, sizeof(struct pred_tab_ent));
     hash_mask = hash_size - 1;
     for (k = 0; k < hash_size; k++) {
       pred_tab[k].pred = 0;
@@ -72,7 +74,6 @@
 
   /* fill predicate table */
   for (dm = &defined_modules[0]; dm->name != 0; dm++) {
-    extern unsigned long enter_atom_body();
     q modname = makesym(enter_atom_body(dm->name, strlen(dm->name)));
     const struct predinfo* const* dp;
     for (dp = &dm->preds[0]; *dp != 0; dp++) {
@@ -92,9 +93,11 @@
   }
 }
 
-static struct pred_tab_ent *find_pred_ent(pred)
-     struct predicate *pred;
+static struct pred_tab_ent*
+find_pred_ent(pred)
+  struct predicate* pred;
 {
+  static int pred_tab_made = 0;
   long h;
   if (!pred_tab_made) {
     make_pred_tab();
@@ -103,7 +106,7 @@
   for (h = HashFunc(pred);
        pred_tab[h].pred != pred;
        h = (h + 1) & hash_mask) {
-    if (pred_tab[h].pred == 0) {
+    if (pred_tab[h].pred == NULL) {
       /* somehow we couldn't find the predicate */
       fatal("Predicate not found in the table");
     }
@@ -314,13 +317,14 @@
 
 static long goal_obj_id = 0;
 
-q make_goal_object(goal, allocp)
-     struct goalrec *goal;
-     q *allocp;
+extern q
+make_goal_object(goal, allocp)
+  struct goalrec* goal;
+  q* allocp;
 {
   declare_globals;
   struct goal_object *obj = (struct goal_object *) allocp;
-  (void) untrace_goal(goal);
+  untrace_goal(goal);
   obj->method_table = &goal_g_data_method_table;
   obj->goal = goal;
   obj->id = goal_obj_id++;
@@ -338,7 +342,6 @@
   struct predicate_object *pred;
   long pred_arity, argv_arity;
   long k;
-  extern q size_of_vector();
 
   if (GD_ARGC != 2) {
     GD_ERROR_IN_NEW("Wrong number of arguments");
