Index: trunk/python2/regfi/pyregfi.h
===================================================================
--- trunk/python2/regfi/pyregfi.h	(revision 198)
+++ trunk/python2/regfi/pyregfi.h	(revision 199)
@@ -49,5 +49,5 @@
 CLASS(KeyIterator, Object)
      PRIVATE REGFI_ITERATOR *iter;
-     PRIVATE const REGFI_NK_REC *next_item;
+     PRIVATE bool first_called;
 
      KeyIterator METHOD(KeyIterator, Con, struct RegistryFile_t *file, char **path,
@@ -56,17 +56,20 @@
      struct ValueIterator_t *METHOD(KeyIterator, list_values);
 
-     void METHOD(KeyIterator, __iter__);
+     KeyIterator METHOD(KeyIterator, __iter__);
      REGFI_NK_REC *METHOD(KeyIterator, iternext);
+
+     int METHOD(KeyIterator, down);
+     int METHOD(KeyIterator, up);
 END_CLASS
 
 /** This is an iterator for reading values from the registry */
 CLASS(ValueIterator, Object)
-    PRIVATE REGFI_ITERATOR *iter;
-    PRIVATE const REGFI_VK_REC *next_item;
+     PRIVATE REGFI_ITERATOR *iter;
+     PRIVATE bool first_called;
+     
+     ValueIterator METHOD(ValueIterator, Con, KeyIterator key);
 
-    ValueIterator METHOD(ValueIterator, Con, KeyIterator key);
-
-    void METHOD(ValueIterator, __iter__);
-    RawData METHOD(ValueIterator, iternext);
+     void METHOD(ValueIterator, __iter__);
+     RawData METHOD(ValueIterator, iternext);
 END_CLASS
 
Index: trunk/python2/regfi/regfi.c
===================================================================
--- trunk/python2/regfi/regfi.c	(revision 198)
+++ trunk/python2/regfi/regfi.c	(revision 199)
@@ -58,8 +58,4 @@
 
   regfi_iterator_free(this->iter);
-  if(this->next_item) {
-    regfi_free_record(this->next_item);
-  }
-
   return 0;
 }
@@ -76,5 +72,5 @@
   talloc_set_destructor((void*)self, KeyIterator_dest);
 
-  // Traverse to the path
+  /* Traverse to the path */
   if(path[0]) {
     if(!regfi_iterator_walk_path(self->iter, (const char **)path)) {
@@ -84,6 +80,6 @@
   }
 
-  // Get the first key in the list
-  self->next_item = regfi_iterator_first_subkey(self->iter);
+  fprintf(stderr, "Con called\n");
+  self->first_called = false;
 
   return self;
@@ -92,22 +88,36 @@
 }
 
-static void KeyIterator__iter__(KeyIterator self) {
-  if(self->next_item) {
-    regfi_free_record(self->next_item);
-  };
-
-  self->next_item = regfi_iterator_first_subkey(self->iter);
-}
+static KeyIterator KeyIterator__iter__(KeyIterator self) {
+  return self;
+}
+
 
 static const REGFI_NK_REC* KeyIterator_next(KeyIterator self) {
-  const REGFI_NK_REC* result;
-
-  if(!self->next_item) return NULL;
-
-  result = self->next_item;
-
-  self->next_item = regfi_iterator_next_subkey(self->iter);
-
+
+  fprintf(stderr, "next called\n");
+
+  if(!self->first_called)
+  {
+    regfi_iterator_first_subkey(self->iter);
+    self->first_called = true;
+  }
+  else
+    regfi_iterator_next_subkey(self->iter);
+    
+  return regfi_iterator_cur_subkey(self->iter);
+}
+
+
+static int KeyIterator_down(KeyIterator self) {
+  fprintf(stderr, "down cur_subkey: %d\n", self->iter->cur_subkey);
+  int result = regfi_iterator_down(self->iter);
+  fprintf(stderr, "down result: %d\n", result);
+  regfi_iterator_first_subkey(self->iter);
+  regfi_iterator_first_value(self->iter);
   return result;
+}
+
+static int KeyIterator_up(KeyIterator self) {
+  return regfi_iterator_up(self->iter);
 }
 
@@ -119,4 +129,6 @@
   VMETHOD(Con) = KeyIterator_Con;
   VMETHOD(iternext) = KeyIterator_next;
+  VMETHOD(down) = KeyIterator_down;
+  VMETHOD(up) = KeyIterator_up;
   VMETHOD(__iter__) = KeyIterator__iter__;
   VMETHOD(list_values) = KeyIterator_list_values;
@@ -126,5 +138,5 @@
   ValueIterator this = (ValueIterator)self;
 
-  if(this->next_item) regfi_free_record(this->next_item);
+  talloc_unlink(this, this->iter);
 
   return 0;
@@ -136,6 +148,4 @@
   talloc_reference(self, self->iter);
 
-  self->next_item = regfi_iterator_first_value(self->iter);
-
   talloc_set_destructor((void *)self, ValueIterator_dest);
 
@@ -143,17 +153,28 @@
 }
 
-static void ValueIterator__iter__(ValueIterator self) {
-  if(self->next_item) regfi_free_record(self->next_item);
-
-  self->next_item = regfi_iterator_first_value(self->iter);
+static ValueIterator ValueIterator__iter__(ValueIterator self) {
+  return self;
 }
 
 static RawData ValueIterator_iternext(ValueIterator self) {
   RawData result;
-  const REGFI_DATA *data;
-  const REGFI_VK_REC *rec = self->next_item;
+  const REGFI_DATA* data;
+  const REGFI_VK_REC* rec;
+
+  if(!self->first_called)
+  {
+    regfi_iterator_first_value(self->iter);
+    self->first_called = true;
+  }
+  else
+    regfi_iterator_next_value(self->iter);
+
+  rec = regfi_iterator_cur_value(self->iter);
 
   if(!rec) return NULL;
 
+  /* XXX: shouldn't parse data here every time we walk over a value.  
+   *      Instead, make data fetching a method and parse it then. 
+   */
   data = (REGFI_DATA *)regfi_iterator_fetch_data(self->iter, rec);
   if(!data) {
@@ -162,5 +183,5 @@
   }
 
-  switch(self->next_item->type) {
+  switch(rec->type) {
   case REG_EXPAND_SZ:
   case REG_SZ:
@@ -178,12 +199,4 @@
   }
 
-
-  /*  if(self->next_item) {
-    regfi_free_record(self->next_item);
-  };
-  */
-
-  self->next_item = regfi_iterator_next_value(self->iter);
-
   return result;
  error:
@@ -255,5 +268,5 @@
 
 void pyregfi_init() {
+  regfi_init();
   INIT_CLASS(RegistryFile);
-
-}
+}
