 +          continue;
 +        }
 +
-+        {
-+          gchar *tmp = uids;
-+          for (; tmp && strlen (tmp); tmp += strlen (tmp) + 1) {
-+            g_debug (G_STRLOC ": adding to index with key %s and data %s", 
-+                     (gchar *)index_dbt.data, tmp);
-+          }
-+        }
-+
 +        /* fill with "uid1\0uid2\0uid3\0..." */
 +        dbt_fill_with_string_array (&id_dbt, uids);
  
          db_error = db->put (db, NULL, &index_dbt, &id_dbt, 0);
  
-@@ -785,6 +873,41 @@ index_add_contact (EBookBackendFileIndex
+@@ -785,6 +854,40 @@ index_add_contact (EBookBackendFileIndex
    }
  }
  

+    gchar *tmp;
+    for (tmp = id_dbt.data; tmp && strlen (tmp); tmp += strlen (tmp) + 1) {
+      gchar *data;
+      g_debug (G_STRLOC ": Considering %s against %s", (gchar *)id_dbt.data, uid);
+      /* if the id is the one we're lookin for then delete! */
+      if (g_str_equal (tmp, uid)) {
+        g_debug (G_STRLOC ": removing from index with id: %s", (gchar *)id_dbt.data);
+
+        /* Remove current str from data */
+        db_error = dbc->c_del (dbc, 0);

+        gchar *tmp;
+        for (tmp = id_dbt.data; tmp && strlen (tmp); tmp += strlen (tmp) + 1) {
+          if (g_str_has_prefix (index_dbt.data, query_key)) {
+            g_ptr_array_add (ids, tmp);
+
+            /* we add it to the list of strings to be freed */
