Index: libabac/abac.c
===================================================================
--- libabac/abac.c	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac.c	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -89,8 +89,8 @@
  * Load an ID cert from a file.
  */
-int abac_context_load_id_file(abac_context_t *ctx, char *filename) {
-    assert(ctx != NULL); assert(filename != NULL);
+int abac_context_load_id_file(abac_context_t *ctx, char *filename, char *keyfilename) {
+    assert(ctx != NULL); assert(filename != NULL); assert(keyfilename!=NULL);
     abac_id_credential_t *id_cert=NULL;
-    int ret = abac_verifier_load_id_file(filename,&id_cert);
+    int ret = abac_verifier_load_id_file(filename,keyfilename,&id_cert);
     if(id_cert) {
         int add_ret = abac_pl_add_type_credential(ctx->pl, id_cert);
@@ -162,13 +162,23 @@
 }
 
+#define KEY_PAT "/*_private.{der,pem}"
 #define ID_PAT "/*_ID.{der,pem}"
 #define ATTR_PAT "/*_attr.der"
-#define ATTR_FILE_PAT "/*_attr.file"
-
+
+char *_make_key_filename(char *cert_file)
+{
+    char *p=strstr(cert_file,"_ID.");
+    char *head=strndup(cert_file,p-cert_file);
+    char *tail=p+4;
+    char *keyfile=NULL;
+    asprintf(&keyfile,"%s_private.%s",head,tail);
+    free(head);
+    return keyfile;
+}
 /**
  * Load a directory full of certs.
  */
 void abac_context_load_directory(abac_context_t *ctx, char *path) {
-    char *glob_pat;
+    char *glob_pat, *key_pat;
     glob_t glob_buf;
     int i, ret;
@@ -184,8 +194,13 @@
     glob(glob_pat, GLOB_BRACE, NULL, &glob_buf); // TODO check for error
     for (i = 0; i < glob_buf.gl_pathc; ++i) {
+        /* blah_ID.pem */
         char *cert_file = glob_buf.gl_pathv[i];
-
-        if(debug) printf("--> ID cert... %s\n", cert_file);
-        ret = abac_context_load_id_file(ctx, cert_file);
+        /* blah_private.pem */
+        char *key_file=_make_key_filename(cert_file);
+        if(debug) {
+            printf("--> ID cert... %s\n", cert_file);
+            printf("--> KEY cert... %s\n", key_file);
+        }
+        ret = abac_context_load_id_file(ctx, cert_file, key_file);
         if (ret != ABAC_CERT_SUCCESS)
             warnx("Couldn't load ID cert %s", cert_file);
Index: libabac/abac.h
===================================================================
--- libabac/abac.h	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac.h	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -27,5 +27,5 @@
 /* see the bottom of the file for possible return codes */
 int abac_context_load_id_id(abac_context_t *ctx, abac_id_t *);
-int abac_context_load_id_file(abac_context_t *ctx, char *filename);
+int abac_context_load_id_file(abac_context_t *ctx, char *filename, char* keyfielname);
 int abac_context_load_id_chunk(abac_context_t *ctx, abac_chunk_t cert);
 int abac_context_load_attribute_attribute(abac_context_t *ctx, abac_attribute_t *);
@@ -134,8 +134,8 @@
 char *abac_term_typed_string(abac_term_t *ptr);
 char *abac_term_string(abac_term_t *ptr);
-char *abac_termtype_name(int i);
 char *abac_term_type_name(abac_term_t *term);
 abac_term_t *abac_term_dup(abac_term_t *ptr);
-abac_term_t *abac_term_create(int type, char *name, abac_condition_t *cptr);
+abac_term_t *abac_term_create(int, char*, abac_condition_t*);
+abac_term_t *abac_term_named_create(int, char*);
 bool abac_term_is_urn_type(abac_term_t *);
 bool abac_term_is_integer_type(abac_term_t *);
@@ -143,4 +143,5 @@
 abac_term_t *abac_term_add_constraint(abac_term_t *ptr, abac_condition_t *cond);
 abac_term_t *abac_term_new(int, char *, char *, abac_aspect_t *);
+abac_term_t *abac_term_named_new(int, char *);
 void abac_term_free(abac_term_t *);
 bool abac_term_is_time_type(abac_term_t *);
@@ -160,5 +161,4 @@
 char *abac_cn_with_sha(char*);
 char *abac_idtype_with_sha(char*);
-char *abac_idtype_string(int);
 abac_stack_t *abac_verifier_dump_creds();
 abac_id_credential_t *abac_verifier_add_id_credential(abac_id_t *a_id);
@@ -180,5 +180,5 @@
 /* from abac_aspect */
 void abac_aspect_free(abac_aspect_t *);
-void abac_errx(int val, char *string);
+void abac_errx(int val, const char *string);
 
 /*
Index: libabac/abac.hh
===================================================================
--- libabac/abac.hh	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac.hh	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -68,5 +68,12 @@
                 if(m_cond) free(m_cond);
               }
-
+            /* this is for named principal data term */
+            DataTerm(char *sha) {
+                if(debug) printf("adding a Dataterm named principal(%s)\n",sha);
+                int isnamed=1;
+                int type=e_TERM_PRINCIPAL;
+                m_term=abac_term_named_create(type,sha);
+            }
+            /* can be an a variable data term or a specific value */
             DataTerm(int type, char *name, Constraint *cond=NULL) {
                 if(debug) printf("adding a Dataterm (%s)\n",name);
@@ -170,7 +177,7 @@
 /* Return the DataTerms bound to this name.  If the name is returned
    in a proof, these will all have values. */
-            std::vector<DataTerm> get_data_terms() {
+            std::vector<DataTerm> get_data_terms(bool &success) {
                 abac_term_t **terms, **end;
-                int i, success_int;
+                int i;
                 terms = abac_param_list_vectorize(abac_aspect_aspect_params(m_role));
                 for (i = 0; terms[i] != NULL; ++i)
@@ -179,4 +186,5 @@
                 std::vector<DataTerm> dataterms = std::vector<DataTerm>(terms, end);
                 abac_terms_free(terms);
+                success=1;
                 return dataterms;
               }
@@ -185,7 +193,7 @@
                 return 1;
               }
-            std::vector<DataTerm> get_linked_data_terms() {
+            std::vector<DataTerm> get_linked_data_terms(bool &success) {
                 abac_term_t **terms, **end;
-                int i, success_int;
+                int i;
                 terms = abac_param_list_vectorize(abac_aspect_linked_role_params(m_role));
                 for (i = 0; terms[i] != NULL; ++i)
@@ -194,4 +202,5 @@
                 std::vector<DataTerm> dataterms = std::vector<DataTerm>(terms, end);
                 abac_terms_free(terms);
+                success=1;
                 return dataterms;
               }
@@ -252,7 +261,7 @@
 /* Return the DataTerms bound to this name.  If the name is returned
    in a proof, these will all have values. */
-            std::vector<DataTerm> get_data_terms() {
+            std::vector<DataTerm> get_data_terms(bool &success) {
                 abac_term_t **terms, **end;
-                int i, success_int;
+                int i;
                 terms = abac_param_list_vectorize(abac_aspect_aspect_params(m_oset));
                 for (i = 0; terms[i] != NULL; ++i)
@@ -261,4 +270,5 @@
                 std::vector<DataTerm> dataterms = std::vector<DataTerm>(terms, end);
                 abac_terms_free(terms);
+                success=1;
                 return dataterms;
               }
@@ -267,7 +277,7 @@
                 return 1;
               }
-            std::vector<DataTerm> get_linked_data_terms() {
+            std::vector<DataTerm> get_linked_data_terms(bool &success) {
                 abac_term_t **terms, **end;
-                int i, success_int;
+                int i;
                 terms = abac_param_list_vectorize(abac_aspect_linked_role_params(m_oset));
                 for (i = 0; terms[i] != NULL; ++i)
@@ -276,4 +286,5 @@
                 std::vector<DataTerm> dataterms = std::vector<DataTerm>(terms, end);
                 abac_terms_free(terms);
+                success=1;
                 return dataterms;
               }
@@ -452,9 +463,7 @@
                 return oset;
               }
-            std::vector<Role> role_tails() {
+            std::vector<Role> role_tails(bool &success) {
                 abac_aspect_t **tails, **end;
-                int i, success_int;
-                char * string=abac_aspect_string(abac_attribute_tail(m_attr));
-                printf("XXX %s XXX\n",string);
+                int i;
                 tails = abac_attribute_tail_vectorized(m_attr);
                 for (i = 0; tails[i] != NULL; ++i)
@@ -463,9 +472,10 @@
                 std::vector<Role> roles = std::vector<Role>(tails, end);
                 abac_aspects_free(tails);
+                success=1;
                 return roles;
               }
-            std::vector<Oset> oset_tails() {
+            std::vector<Oset> oset_tails(bool &success) {
                 abac_aspect_t **tails, **end;
-                int i, success_int;
+                int i;
                 tails = abac_attribute_tail_vectorized(m_attr);
                 for (i = 0; tails[i] != NULL; ++i)
@@ -473,4 +483,5 @@
                 end = &tails[i];
                 std::vector<Oset> osets = std::vector<Oset>(tails, end);
+                success=1;
                 abac_aspects_free(tails);
                 return osets;
@@ -501,5 +512,7 @@
             void write_cert(char *filename) {
                 FILE *out = fopen(filename, "w");
+                printf("writing to %s\n", filename);
                 write_cert(out);
+                printf("done writing to %s\n", filename);
                 fclose(out);
               }
@@ -535,6 +548,6 @@
                 return abac_context_load_id_id(m_ctx, id.id());
               }
-            int load_id_file(char *filename) {
-                return abac_context_load_id_file(m_ctx, filename);
+            int load_id_file(char *filename, char *keyfilename) {
+                return abac_context_load_id_file(m_ctx, filename, keyfilename);
               }
             int load_id_chunk(abac_chunk_t cert) { 
Index: libabac/abac_aspect.c
===================================================================
--- libabac/abac_aspect.c	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac_aspect.c	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -33,4 +33,5 @@
 
     char *principal_name;
+    char *principal_name_p; // pPrincipal_name
     abac_term_t *principal_object;
 
@@ -200,5 +201,7 @@
     if(USE("ABAC_CN"))
         return abac_cn_with_sha(ptr->principal_name);
-    return ptr->principal_name;
+    if(ABAC_IN_PROLOG) {
+        return ptr->principal_name_p;
+    } else return ptr->principal_name;
 }
 
@@ -206,4 +209,6 @@
 {
     assert(ptr);
+    if(ABAC_IN_PROLOG)
+        return ptr->principal_name_p;
     return ptr->principal_name;
 }
@@ -283,4 +288,5 @@
 
     if(ptr->principal_name) free(ptr->principal_name);
+    if(ptr->principal_name_p) free(ptr->principal_name_p);
     if(ptr->linked_role_name) free(ptr->linked_role_name);
     if(ptr->aspect_name) free(ptr->aspect_name);
@@ -348,4 +354,5 @@
     ptr->is_object=0;
     ptr->principal_name = NULL;
+    ptr->principal_name_p = NULL;
     ptr->aspect_type=e_ASPECTTYPE_NULL;
 
@@ -372,4 +379,5 @@
     ptr->aspect_type=type;
     ptr->principal_name = strdup(principal_name);
+    ptr->principal_name_p =  prologIt(principal_name);
     if(type==e_ASPECTTYPE_ROLE)
        ptr->type_string=abac_xstrdup("role");
@@ -386,7 +394,5 @@
 abac_aspect_t *abac_aspect_role_principal_create(char *principal_name)
 {
-    char *tmp=NULL;
-    asprintf(&tmp,"p%s",principal_name);
-    return abac_aspect_principal_new(e_ASPECTTYPE_ROLE,tmp);
+    return abac_aspect_principal_new(e_ASPECTTYPE_ROLE,principal_name);
 }
 
@@ -398,7 +404,5 @@
 abac_aspect_t *abac_aspect_oset_principal_create(char *principal_name)
 {
-    char *tmp=NULL;
-    asprintf(&tmp,"p%s",principal_name);
-    return abac_aspect_principal_new(e_ASPECTTYPE_OSET,tmp);
+    return abac_aspect_principal_new(e_ASPECTTYPE_OSET,principal_name);
 }
 
@@ -434,4 +438,5 @@
 
     ptr->principal_name = strdup(principal_name);
+    ptr->principal_name_p = prologIt(principal_name);
     ptr->aspect_type=type;
 
@@ -456,7 +461,5 @@
 abac_aspect_t *abac_aspect_oset_create(char *principal_name, char *oset_name)
 {
-    char *tmp=NULL;
-    asprintf(&tmp,"p%s",principal_name);
-    return abac_aspect_new(e_ASPECTTYPE_OSET,tmp,oset_name);
+    return abac_aspect_new(e_ASPECTTYPE_OSET,principal_name,oset_name);
 }
 
@@ -468,7 +471,5 @@
 abac_aspect_t *abac_aspect_role_create(char *principal_name, char *role_name)
 {
-    char *tmp=NULL;
-    asprintf(&tmp,"p%s",principal_name);
-    return abac_aspect_new(e_ASPECTTYPE_ROLE,tmp,role_name);
+    return abac_aspect_new(e_ASPECTTYPE_ROLE,principal_name,role_name);
 }
 
@@ -492,4 +493,5 @@
     ptr->aspect_type=type;
     ptr->principal_name = strdup(principal_name);
+    ptr->principal_name_p = prologIt(principal_name);
 
     ptr->linked_role_name = strdup(linked_role_name);
Index: libabac/abac_attribute.c
===================================================================
--- libabac/abac_attribute.c	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac_attribute.c	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -76,8 +76,6 @@
     char *name=abac_aspect_aspect_name(head);
 
-/* XXX ????
     if (abac_id_privkey(issuer_id) == NULL)
         return ABAC_ATTRIBUTE_ISSUER_NOKEY;
-*/
     if (!abac_validate_clean_aspect_name(name))
         return ABAC_ATTRIBUTE_INVALID_ROLE;
@@ -145,4 +143,5 @@
         BUILD_END
     );
+
     if (attr_cert == NULL)
         return 0;
Index: libabac/abac_common.h
===================================================================
--- libabac/abac_common.h	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac_common.h	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -11,5 +11,5 @@
 } abac_idtype_t;
 /* idtypename[idtype] */
-static char * const _idtypename[] =
+static const char * const _idtypename[] =
 {
   "badidtype", "keyid"
@@ -28,5 +28,5 @@
 } abac_termtype_t;
 /* termname[dtermtype] */
-static char *const _termname[] =
+static const char *const _termname[] =
 {
   "badterm",
@@ -49,5 +49,5 @@
 
 /* condname[condtype] */
-static char *const _condname[] =
+static const char *const _condname[] =
 {
   "badcondition",
Index: libabac/abac_internal.h
===================================================================
--- libabac/abac_internal.h	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac_internal.h	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -17,4 +17,17 @@
 abac_id_t *abac_id_keyid_new(char *keyid, char *cn, certificate_t *cert);
 
+char *abac_termtype_string(int i);
+char *abac_idtype_string(int);
+
+extern int ABAC_IN_PROLOG;
+extern char *prologIt(char*);
+
+#define PROLOG(BODY) {  \
+    ABAC_IN_PROLOG++;      \
+    { BODY }               \
+    ABAC_IN_PROLOG--;      \
+} 
+
+
 #endif /* __ABAC_I_H__ */
 
Index: libabac/abac_pl_gen.c
===================================================================
--- libabac/abac_pl_gen.c	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac_pl_gen.c	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -1,6 +1,10 @@
-
 
 /***********************************************************************/
-/* clause generation called from parser to generate credential clauses */
+/* clause generation called  to  generate credential clauses with a    */
+/* given credential syntax structure (made from parser or from a       */
+/* pre-existing structure                                              */
+/* There are 2 passes,                                                 */
+/*  first pass, process named cred id, and constraint range/role/oset  */
+/*  2nd pass, process rule left / right                                */
 /***********************************************************************/
 #include <stdio.h>
@@ -18,6 +22,8 @@
 
 static int debug=0;
+int ABAC_IN_PROLOG=0;
 
 extern int using_this;
+
 
 extern char* abac_yyfptr_encoded;
@@ -29,4 +35,11 @@
 
 /***********************************************************************/
+char *prologIt(char *str)
+{
+    char *tmp=NULL;
+    asprintf(&tmp,"p%s",str);
+    return tmp;
+}
+
 static char* isX()
 {
@@ -69,5 +82,6 @@
 {
      char *tmp=NULL;
-     char *principalname=abac_aspect_principal_name(ptr);
+     char *principalname;
+     PROLOG(principalname=abac_aspect_principal_name(ptr););
      char *aspectname=abac_aspect_aspect_name(ptr);
      char *typestring=abac_aspect_type_string(ptr);
@@ -78,5 +92,5 @@
      abac_param_list_t *aspect_params=abac_aspect_aspect_params(ptr);
      if(aspect_params) {
-        param_string=abac_param_list_string(aspect_params);
+        PROLOG(param_string=abac_param_list_string(aspect_params););
      }
 
@@ -117,5 +131,6 @@
          return tmp;
      } else {
-         char *principalname=abac_aspect_principal_name(ptr);
+         char *principalname;
+         PROLOG(principalname=abac_aspect_principal_name(ptr););
          char *aspectname=abac_aspect_aspect_name(ptr);
          char *linkedname=abac_aspect_linked_role_name(ptr);
@@ -128,10 +143,10 @@
          abac_param_list_t *aspect_params=abac_aspect_aspect_params(ptr);
          if(aspect_params) {
-            param_string=abac_param_list_string(aspect_params);
+            PROLOG(param_string=abac_param_list_string(aspect_params););
          }
     
          abac_param_list_t *linked_role_params=abac_aspect_linked_role_params(ptr);
          if(linked_role_params) {
-            linked_param_string=abac_param_list_string(linked_role_params);
+            PROLOG(linked_param_string=abac_param_list_string(linked_role_params););
          }
     
Index: libabac/abac_pl_yap.c
===================================================================
--- libabac/abac_pl_yap.c	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac_pl_yap.c	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -23,5 +23,4 @@
 extern abac_aspect_t *abac_yy_get_rule_tail_aspect();
 extern abac_aspect_t *abac_yy_get_rule_head_aspect();
-
 
 static int debug=0;
@@ -298,6 +297,6 @@
         _show_yap_db("DEBUG:calling within _query_with_aspect");
 
-    
-    char *nm=abac_aspect_principal_name(head);
+    char *nm;
+    PROLOG(nm=abac_aspect_principal_name(head););
 
     /* could be obj or principal */
@@ -306,5 +305,5 @@
         prin_nm=abac_aspect_object_name(tail);
         } else {
-            prin_nm=abac_aspect_principal_name(tail);
+            PROLOG(prin_nm=abac_aspect_principal_name(tail););
     }
 
@@ -320,5 +319,8 @@
 
     if(debug) printf("printing up the yap query ..\n");
-    char *pstring=abac_aspect_aspect_param_string(head);
+
+    char *pstring;
+    PROLOG(pstring=abac_aspect_aspect_param_string(head););
+
     char *stub=abac_aspect_type_string(head);
     if(pstring) {
Index: libabac/abac_pl_yy.c
===================================================================
--- libabac/abac_pl_yy.c	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac_pl_yy.c	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -257,4 +257,7 @@
     abac_yy_id_cert_t *id_cert=NULL;
 
+    if(debug) {
+         printf("add_yy_id_certs: adding --> (%s)\n", principalname);
+    }
     int found=0;
     abac_yy_id_cert_t *cur;
@@ -273,7 +276,13 @@
             id_cert->principalname=abac_xstrdup(principalname);
             id_cert->type=type;
-            id_cert->clause=generate_pl_type_clause(principalname,type);
+            if(USE("ABAC_CN")) {
+                 id_cert->clause=generate_pl_type_clause(principalname,type);
+                 } else {
+                    int *tmp=NULL;
+                    asprintf(&tmp,"p%s",principalname);
+                    id_cert->clause=generate_pl_type_clause(tmp,type);
+                    free(tmp);
+            }
             abac_list_add(abac_yy_id_certs, id_cert);
-            if(debug) printf("  -> adding yy id certs %s\n", principalname);
     }
 }
@@ -884,5 +893,5 @@
 void make_yy_range_numeric_constraint(abac_yy_term_data_t *ptr, char *var)
 {
-   char *typestr=abac_termtype_name(ptr->type);
+   char *typestr=abac_termtype_string(ptr->type);
    abac_list_t *rlist=get_yy_term_data_cond_range(ptr);
    char *tmplist=NULL;
@@ -930,5 +939,5 @@
 void make_yy_range_time_constraint(abac_yy_term_data_t *ptr, char *var)
 {
-   char *typestr=abac_termtype_name(ptr->type);
+   char *typestr=abac_termtype_string(ptr->type);
    abac_list_t *rlist=get_yy_term_data_cond_range(ptr);
    char *tmplist=NULL;
@@ -989,5 +998,5 @@
 void make_yy_range_string_constraint(abac_yy_term_data_t *ptr, char *var)
 {
-   char *typestr=abac_termtype_name(ptr->type);
+   char *typestr=abac_termtype_string(ptr->type);
    abac_list_t *rlist=get_yy_term_data_cond_range(ptr);
    char *tmplist=NULL;
@@ -1046,9 +1055,14 @@
     abac_yy_term_t *curr = terms;
     int type;
+    int isnamed;
+    char *name;
+    char *cond;
+    void *ptr;
 
     while (curr) {
-        char *name=NULL;
-        char *cond=NULL;
-        void *ptr=NULL;
+        name=NULL;
+        cond=NULL;
+        ptr=NULL;
+        isnamed=0; 
         switch (curr->type) {
            case e_yy_DTERM_DATA:
@@ -1079,19 +1093,18 @@
               type=pptr->type;
               name=abac_xstrdup(get_yy_principal_name(pptr));
-              cond=NULL;
-              ptr=NULL;
+              isnamed=1; 
               break;
            }
            case e_yy_DTERM_ANONYMOUS:
            {
-              type=0;
+              type=abac_term_verify_term_type("anonymous");
               name=abac_xstrdup("_");
-              cond=NULL;
-              ptr=NULL;
               break;
            }
        }
-
-       abac_term_t *param=abac_term_new(type,name,cond,ptr);
+       abac_term_t *param=NULL;
+       if(isnamed)
+           param=abac_term_named_new(type,name);
+           else param=abac_term_new(type,name,cond,ptr);
        if (linked) 
            abac_aspect_add_linked_param(aspect_ptr, param);
@@ -1175,5 +1188,4 @@
          else ptr=abac_aspect_role_principal_new(principalname);
      _add_yy_id_certs(othername,get_yy_principal_type(principal));
-
      if (ptr==NULL)
          goto error;
Index: libabac/abac_term.c
===================================================================
--- libabac/abac_term.c	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac_term.c	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -30,8 +30,15 @@
 };
 
+/* termtype_t/name pair for the data terms
+   idtype_t/name/p_name pair for the named principal term
+*/
+   
 struct _abac_term_t {
     int type;
     char *name;
-    char *cn;
+    // e_TERM_PRINCIPAL isnamed
+    int isnamed;
+    char *p_name; 
+    char *cn; //XXX ?? might not need this at all
     abac_condition_t *constraint;
 }; 
@@ -48,5 +55,5 @@
     if(i>_condname_cnt)
         panic("abac_condtype_name: went out of range on condname");
-    return _condname[i];
+    return (char *) _condname[i];
 }
 
@@ -155,6 +162,15 @@
 /******************************************************************/
 
+int abac_term_isnamed(abac_term_t *term)
+{
+    if(term->isnamed) return 1;
+       else return 0;
+}
+
 char *abac_term_name(abac_term_t *term)
 {
+    if(ABAC_IN_PROLOG && term->p_name) {
+        return term->p_name;
+    }
     return term->name;
 }
@@ -170,14 +186,16 @@
 }
 
-char *abac_termtype_name(int i)
+char *abac_termtype_string(int i)
 {
     if(i>_termname_cnt)
-        panic("abac_termtype_name: went out of range on termname");
-    return _termname[i];
+        panic("abac_termtype_string: went out of range on termname");
+    return (char *) _termname[i];
 }
 
 char *abac_term_type_name(abac_term_t *term)
 {
-    return abac_termtype_name(term->type);
+    if(term->isnamed)
+        return abac_idtype_string(term->type);
+    return abac_termtype_string(term->type);
 }
 
@@ -262,5 +280,5 @@
      if(debug) {
          printf("abac_term_new: \n");
-         printf("  type is %d(%s)\n", type, abac_termtype_name(type));
+         printf("  type is %d(%s)\n", type, abac_termtype_string(type));
          printf("  name is (%s)\n", name);
          if(cond)
@@ -283,5 +301,7 @@
      }
      abac_term_t *ptr=abac_xmalloc(sizeof(abac_term_t));
+     ptr->isnamed=0;
      ptr->type=type;
+     ptr->p_name=NULL;
      /* reformat the term name if it is a time type */
      if((!constraint) && _abac_termtype_is_time_type(type) && isdigit(name[0])) {
@@ -292,4 +312,5 @@
      }
      ptr->constraint=constraint;
+     ptr->cn=NULL;
      return ptr;
 }
@@ -299,5 +320,5 @@
      if(debug) {
          printf("abac_term_create: \n");
-         printf("  type is %d(%s)\n", type, abac_termtype_name(type));
+         printf("  type is %d(%s)\n", type, abac_termtype_string(type));
          printf("  name is (%s)\n", name);
          if(cptr)
@@ -307,5 +328,7 @@
 
      abac_term_t *ptr=abac_xmalloc(sizeof(abac_term_t));
+     ptr->isnamed=0;
      ptr->type=type;
+     ptr->p_name=NULL;
      /* reformat the term name if it is a time type */
      if((!cptr) && _abac_termtype_is_time_type(type) && isdigit(name[0])) {
@@ -316,4 +339,47 @@
      }
      ptr->constraint=(cptr==NULL)?NULL:abac_condition_dup(cptr);
+     ptr->cn=NULL;
+     return ptr;
+}
+
+/* called from yy, named principal type */
+abac_term_t *abac_term_named_new(int idtype, char *name)
+{
+     if(debug) {
+         printf("abac_term_named_new: \n");
+         printf("  type is %d(%s)\n", idtype, abac_idtype_string(idtype));
+         printf("  name is (%s)\n", name);
+     }
+     abac_term_t *ptr=abac_xmalloc(sizeof(abac_term_t));
+     ptr->isnamed=1;
+     ptr->type=idtype;
+     ptr->name=abac_xstrdup(name);
+     ptr->p_name=NULL;
+     /* if ABAC_CN, no need to attach p */
+     if(!USE("ABAC_CN"))
+         asprintf(&ptr->p_name,"p%s",name);
+     ptr->constraint=NULL;
+     ptr->cn=NULL;
+     return ptr;
+}
+
+abac_term_t *abac_term_named_create(int idtype, char *name)
+{
+     if(debug) {
+         printf("abac_term_named_create: \n");
+         printf("  type is %d(%s)\n", idtype, abac_idtype_string(idtype));
+         printf("  name is (%s)\n", name);
+     }
+
+     abac_term_t *ptr=abac_xmalloc(sizeof(abac_term_t));
+     ptr->isnamed=1;
+     ptr->type=idtype;
+     ptr->name=abac_xstrdup(name);
+     ptr->p_name=NULL;
+     /* if ABAC_CN, no need to attach p */
+     if(!USE("ABAC_CN"))
+         asprintf(&ptr->p_name,"p%s",name);
+     ptr->constraint=NULL;
+     ptr->cn=NULL;
      return ptr;
 }
@@ -323,9 +389,13 @@
      assert(ptr);
      abac_term_t *nptr=abac_xmalloc(sizeof(abac_term_t));
+     nptr->isnamed=ptr->isnamed;
      nptr->type=ptr->type;
      nptr->name=abac_xstrdup(ptr->name);
+     nptr->p_name=(ptr->p_name==NULL)?NULL:abac_xstrdup(ptr->p_name);
      if(ptr->constraint!=NULL)
         nptr->constraint=abac_condition_dup(ptr->constraint);
         else nptr->constraint=NULL;
+     nptr->cn=(ptr->cn)==NULL?NULL:abac_xstrdup(ptr->cn);
+        nptr->cn=abac_xstrdup(ptr->cn);
      return nptr;
 }
@@ -337,4 +407,6 @@
     }
     free(ptr->name);
+    if(ptr->p_name) free(ptr->p_name);
+    if(ptr->cn) free(ptr->cn);
     free(ptr);
 }
@@ -384,33 +456,7 @@
 }
 
-/* len of name or name:cond */
-static int abac_term_len_with_condition(abac_term_t *ptr)
-{
-    char *cond=NULL;
-    char *name=ptr->name;
-    int len=strlen(name);
-    if(ptr->constraint) {
-       cond=abac_condition_string(ptr->constraint);
-       len=len+strlen(cond)+1;
-       free(cond); 
-    }
-    return len;
-}
-
-/* just name */
 char *abac_term_string(abac_term_t *ptr)
 {
-    return abac_xstrdup(ptr->name);
-}
-
-/* just len of name */
-static int abac_term_len(abac_term_t *ptr)
-{
-    /* including the 2 's */
-    if(ptr->type == abac_term_verify_term_type("urn") ||
-              ptr->type == abac_term_verify_term_type("string") ) {
-        return strlen(ptr->name)+2; 
-    }
-    return strlen(ptr->name);
+    return abac_xstrdup(abac_term_name(ptr));
 }
 
Index: libabac/abac_util.c
===================================================================
--- libabac/abac_util.c	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac_util.c	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -225,5 +225,5 @@
 
 
-void abac_errx(int val, char *string)
+void abac_errx(int val, const char *string)
 {
     errx(val, "%s", string);
Index: libabac/abac_util.h
===================================================================
--- libabac/abac_util.h	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac_util.h	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -18,5 +18,5 @@
 int abac_validate_clean_aspect_name(char *string);
 chunk_t abac_generate_serial();
-void abac_errx(int,char*);
+void abac_errx(int,const char*);
 
 #ifdef DEBUG
Index: libabac/abac_verifier.c
===================================================================
--- libabac/abac_verifier.c	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac_verifier.c	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -5,4 +5,8 @@
 // include the GNU extension of asprintf
 #define _GNU_SOURCE
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 #include <assert.h>
@@ -192,6 +196,5 @@
     abac_id_credential_t *id_cred;
     char *cn=abac_id_cn(a_id);
-    char *keyid=NULL;
-    asprintf(&keyid,"p%s",abac_id_keyid(a_id));
+    char *keyid=abac_id_keyid(a_id);
 
     // add the abac_id to the map of id credentials
@@ -204,5 +207,5 @@
         id_cred->pl_clause = generate_pl_type_clause(cn, abac_id_idtype(a_id));
         } else {
-           id_cred->pl_clause=generate_pl_type_clause(keyid, abac_id_idtype(a_id));
+           id_cred->pl_clause=generate_pl_type_clause(prologIt(keyid), abac_id_idtype(a_id));
     }
     HASH_ADD_KEYPTR(hh, id_creds, id_cred->hashkeyid, strlen(id_cred->hashkeyid), id_cred);
@@ -220,5 +223,5 @@
 static int _load_id(abac_id_t **a_id,certificate_t *cert, abac_id_credential_t **id_cred_ret) {
     abac_id_credential_t *id_cred = NULL;
-    char *okeyid, *keyid = NULL;
+    char *keyid = NULL;
     chunk_t id;
     int ret;
@@ -229,6 +232,5 @@
     // get the key ID, add p to keyid SHA here */
     id = x509->get_subjectKeyIdentifier(x509);
-    okeyid = _chunk_to_string(id);
-    asprintf(&keyid,"p%s",okeyid);
+    keyid = _chunk_to_string(id);
 
     /* Mike said this is the way it is */
@@ -268,5 +270,5 @@
     // success, add a new abac_id
     if(*a_id ==NULL)
-        *a_id = abac_id_keyid_new(okeyid,cn,cert);
+        *a_id = abac_id_keyid_new(keyid,cn,cert);
 
     abac_id_credential_t *n_id_cred=abac_verifier_add_id_credential(*a_id);
@@ -319,13 +321,23 @@
 }
 
+int _exist(char *filename)
+{
+   struct stat stbuf;
+   if(stat(filename,&stbuf) == -1)
+       return 0;
+   return 1;
+}
+
 /**
  * Load an ID cert from a file.
  */
-int abac_verifier_load_id_file(char *filename, abac_id_credential_t **id_cred_ret) {
+int abac_verifier_load_id_file(char *filename, char *keyfilename, abac_id_credential_t **id_cred_ret) {
     abac_id_t *id=NULL;
     if (lib == NULL)
         errx(1, "looks like you didn't call libabac_init() (lib is NULL)");
 
-    // load the cert
+    if(debug) printf("loading id file... %s\n", filename);
+
+    // load the cert, with pubic key
     certificate_t *cert = lib->creds->create(
         lib->creds, CRED_CERTIFICATE, CERT_X509,
@@ -334,7 +346,19 @@
         BUILD_END
     );
+
     if (cert == NULL)
         return ABAC_CERT_INVALID;
-    return _load_id(&id,cert,id_cred_ret);
+
+    int rc=_load_id(&id,cert,id_cred_ret);
+    /* try to load the private key if it is there */
+    if(_exist(keyfilename)) {
+        if(debug) printf("loading... %s\n", keyfilename);
+        int keyrc=abac_id_load_privkey(id, keyfilename);
+        if(debug) {
+           if(keyrc == 1) printf("..load_id_file: load(%s) with a private key\n",filename);
+               else printf("..load_id_file: load(%s) without a private key\n",filename);
+        }
+    }
+    return rc;
 }
 
@@ -441,4 +465,10 @@
 
     HASH_FIND_STR(id_creds, principalname, id_cred);
+    if(id_cred == NULL) {
+        ret = ABAC_CERT_MISSING_ISSUER;
+        if(debug)
+             printf("can not find %s in id_creds\n", principalname);
+        goto error;
+    }
     issuer_id=id_cred->id;
     if (issuer_id == NULL) {
@@ -551,4 +581,5 @@
 int abac_verifier_load_attribute_cert_file(char *filename, abac_credential_t **cred) {
     // load the cert
+    if(debug) printf("..loading attr file %s\n", filename);
     certificate_t *cert = lib->creds->create(
         lib->creds, CRED_CERTIFICATE, CERT_X509_AC,
Index: libabac/abac_verifier.h
===================================================================
--- libabac/abac_verifier.h	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/abac_verifier.h	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -12,5 +12,5 @@
 
 int abac_verifier_load_id_id(abac_id_t*, abac_id_credential_t **id_cert);
-int abac_verifier_load_id_file(char *filename, abac_id_credential_t **id_cert);
+int abac_verifier_load_id_file(char *filename, char*, abac_id_credential_t **id_cert);
 int abac_verifier_load_id_chunk(chunk_t chunk, abac_id_credential_t **id_cert);
 int abac_verifier_load_attribute_cert_attribute(abac_attribute_t *, abac_credential_t **cred);
Index: libabac/rt2.y
===================================================================
--- libabac/rt2.y	(revision 13c94790b69ae17f32323473de761f090e9d4a35)
+++ libabac/rt2.y	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -145,5 +145,8 @@
                int idtype=abac_verify_idtype_type($2);
                char *tmp=NULL;
+/* XXX
                asprintf(&tmp,"p%s",$5);
+*/
+               asprintf(&tmp,"%s",$5);
                char *cn=abac_cn_with_sha(tmp);
                if(cn && idtype)  {
