Index: libabac/abac.c
===================================================================
--- libabac/abac.c	(revision 63dcd99b21d5dd91967b16a476f1cd8f2dcbd366)
+++ libabac/abac.c	(revision cd0ef6145345dee65e5d64f7cf4b933e9596fd86)
@@ -132,7 +132,7 @@
                 abac_credential_free(cred);
             );
+            abac_list_free(cred_list);
         }
     }
-    abac_list_free(cred_list);
     return ret;
 }
@@ -211,8 +211,5 @@
     int i = 0;
 
-    assert(ctx != NULL);
-    assert(role != NULL);
-    assert(principal != NULL);
-    assert(success != NULL);
+    assert(ctx != NULL); assert(role != NULL); assert(principal != NULL); assert(success != NULL);
 
     abac_graph_t *result_graph = abac_graph_query(ctx->graph, role, principal);
Index: libabac/abac_attribute.c
===================================================================
--- libabac/abac_attribute.c	(revision 63dcd99b21d5dd91967b16a476f1cd8f2dcbd366)
+++ libabac/abac_attribute.c	(revision cd0ef6145345dee65e5d64f7cf4b933e9596fd86)
@@ -365,12 +365,6 @@
 
     char **rt0s=read_credential((void *)id_certs,filename, &xml, km);
-    if(rt0s == NULL) {
-        abac_keyid_map_free(km);
-        return alist;
-    }
-    if(xml == NULL || strlen(xml)==0) {
-        abac_keyid_map_free(km);
-        return alist;
-    }
+    if(rt0s == NULL) return alist;
+    if(xml == NULL || strlen(xml)==0) return alist;
 
     abac_attribute_t *attr;
@@ -403,5 +397,5 @@
     if(chunk.len==0) return alist;
 
-    char **rt0s=get_rt0_from_xml(id_certs, xml, km);
+    char **rt0s=get_rt0_from_xml((void *) id_certs, xml, km);
     char *rt0=NULL;
     if(rt0s==NULL) return alist;
Index: libabac/abac_graph.c
===================================================================
--- libabac/abac_graph.c	(revision 63dcd99b21d5dd91967b16a476f1cd8f2dcbd366)
+++ libabac/abac_graph.c	(revision cd0ef6145345dee65e5d64f7cf4b933e9596fd86)
@@ -13,5 +13,4 @@
     abac_role_t *role;
     char *name;
-    int refcount;
 
     abac_list_t *edges;
@@ -26,5 +25,4 @@
 // edge
 typedef struct _abac_edge_t {
-    int refcount;
     abac_vertex_t *vertex;
     abac_vertex_t *reverse_vertex;
@@ -85,9 +83,7 @@
     return clone;
 }
-/**
- * Add a vertex to the graph. Should only be called by
- * abac_graph_add_credential. This returns an existing vertex with the refcount
- * bumped, or a new vertex with a refcount of 1.  Either way it gets and
- * references the vertex.
+
+/**
+ * Add a vertex to the graph. Should only be called by abac_graph_add_credential.
  */
 static abac_vertex_t *_get_vertex(abac_graph_t *graph, abac_role_t *role) {
@@ -101,5 +97,4 @@
     if (vertex == NULL) {
         vertex = abac_xmalloc(sizeof(abac_vertex_t));
-        vertex->refcount = 0;
         vertex->role = abac_role_dup(role);
         vertex->name = abac_role_string(vertex->role);
@@ -118,5 +113,4 @@
                 abac_vertex_t *tail_vertex = _get_vertex(graph, prereq);
                 abac_list_add(vertex->prereqs, tail_vertex);
-                printf("XXX add a prereq to vertex\n");
             );
         }
@@ -129,94 +123,6 @@
         HASH_ADD_KEYPTR(hh, graph->vertices, vertex->name, strlen(vertex->name), vertex);
     }
-    vertex->refcount++;
 
     return vertex;
-}
-
-/* forward decl */
-static void _free_edge(abac_edge_t *edge);
-/*
- * Reduce the vertex reference count and free it if this is the last reference
- */
-static void _free_vertex(abac_vertex_t *vertex) {
-    abac_edge_t *edge=NULL;
-    abac_vertex_t *pre=NULL;
-
-    --vertex->refcount;
-
-    if ( vertex->refcount > 0) return;
-
-    abac_role_free(vertex->role);
-
-    abac_list_foreach(vertex->edges, edge,
-        _free_edge(edge);
-    );
-    abac_list_free(vertex->edges);
-
-    abac_list_foreach(vertex->reverse_edges, edge,
-        _free_edge(edge);
-    );
-    abac_list_free(vertex->reverse_edges);
-
-    // Free the prereqs
-    if (vertex->prereqs != NULL) {
-        abac_list_foreach(vertex->prereqs, pre,
-            if (pre != NULL) {
-                _free_vertex(pre);
-                printf("YYY free a prereq to vertex\n");
-            }
-        );
-        abac_list_free(vertex->prereqs);
-    }
-
-    free(vertex);
-}
-
-/*
- * Increment vertex reference count
- */
-static abac_vertex_t *_dup_vertex(abac_vertex_t *v) {
-    v->refcount++;
-    return v;
-}
-
-
-/*
- * create a new edge from the given head, tail and credential
- */
-
-static abac_edge_t *_get_edge(abac_vertex_t *h, abac_vertex_t *t,
-        abac_credential_t *c) {
-
-    /* An edge does not own it's vertices.  Do not delete them from an edge
-     * reference. */
-    abac_edge_t *edge = abac_xmalloc(sizeof(abac_edge_t));
-    edge->refcount = 1;
-    edge->vertex = t;
-    edge->reverse_vertex = h;
-    /* Don't dup a null credential */
-    edge->credential = (c) ? abac_credential_dup(c): NULL;
-
-    return edge;
-}
-
-
-/**
- * Increment the reference count
- */
-static abac_edge_t *_dup_edge(abac_edge_t *e) {
-    e->refcount++;
-    return e;
-}
-
-/**
- * Decerement the refcount and free it if this was the last reference.  NB
- * edges do not own teh vertices, so they must be deleted elsewhere.
- */
-static void _free_edge(abac_edge_t *edge) {
-    assert(edge && edge->refcount > 0);
-    if ( --edge->refcount > 0) return;
-    if (edge->credential) abac_credential_free(edge->credential);
-    free(edge);
 }
 
@@ -241,16 +147,16 @@
     // make sure we don't insert the same edge twice (ugh)
     abac_list_foreach(head_vertex->edges, edge,
-        if (edge->vertex == tail_vertex) {
-            _free_vertex(head_vertex);
-            _free_vertex(tail_vertex);
+        if (edge->vertex == tail_vertex)
             return 0;
-        }
     );
 
     // create the edge and add it
-    edge = _get_edge(head_vertex, tail_vertex, cred);
+    edge = abac_xmalloc(sizeof(abac_edge_t));
+    edge->vertex = tail_vertex;
+    edge->reverse_vertex = head_vertex;
+    edge->credential = abac_credential_dup(cred);
 
     abac_list_add(head_vertex->edges, edge);
-    abac_list_add(tail_vertex->reverse_edges, _dup_edge(edge));
+    abac_list_add(tail_vertex->reverse_edges, edge);
 
     // must re-derive edges
@@ -294,5 +200,5 @@
 
         free(current);
-        _free_edge(tail);
+        free(tail);
     }
 }
@@ -310,7 +216,10 @@
     debug_printf("derived edge %s <- %s\n", head->name, tail->name);
 
-    edge = _get_edge(head, tail, NULL);
+    edge = abac_xmalloc(sizeof(abac_edge_t));
+    edge->vertex = tail;
+    edge->reverse_vertex = head;
+    edge->credential = NULL;
     abac_list_add(head->edges, edge);
-    abac_list_add(tail->reverse_edges, _dup_edge(edge));
+    abac_list_add(tail->reverse_edges, edge);
 
     // add to list of derived edges
@@ -698,5 +607,19 @@
     while ((vertex = graph->vertices) != NULL) {
         HASH_DEL(graph->vertices, vertex);
-        _free_vertex(vertex);
+
+        abac_role_free(vertex->role);
+
+        abac_list_foreach(vertex->edges, edge,
+            if (edge->credential != NULL)
+                abac_credential_free(edge->credential);
+            free(edge);
+        );
+        abac_list_free(vertex->edges);
+
+        // the prereq vertices will be freed by the outer while loop
+        if (vertex->prereqs != NULL)
+            abac_list_free(vertex->prereqs);
+
+        free(vertex);
     }
 
