diff --git a/sites/all/modules/entity_dependency/EntityDependencyIterator.inc b/sites/all/modules/entity_dependency/EntityDependencyIterator.inc
index 47fa6a6..454e95e 100644
--- a/sites/all/modules/entity_dependency/EntityDependencyIterator.inc
+++ b/sites/all/modules/entity_dependency/EntityDependencyIterator.inc
@@ -90,10 +90,8 @@ class EntityDependencyIterator implements RecursiveIterator {
     $this->entities = $entities;
 
     if (empty($parent)) {
-      foreach ($this->entities as $entity_type => $entity_ids) {
-        foreach ($entity_ids as $entity_id => $somethings) {
-          $this->causes[$entity_type][$entity_id] = FALSE;
-        }
+      foreach ($this->entities as $key => $entity) {
+        $this->causes[$entity['type']][$entity['id']] = FALSE;
       }
     }
     else {
@@ -110,46 +108,33 @@ class EntityDependencyIterator implements RecursiveIterator {
    * @return boolean
    */
   public function hasChildren() {
-    $current = current($this->entities);
-    if (is_array($current)) {
-      return TRUE;
-    }
-
+    $current = $this->current;
     // Don't check for dependencies twice.
-    if (!isset($this->checked[$this->entityType][$this->entityId]) && !empty($this->entityId)) {
+    if (!empty($this->current['id']) && !isset($this->checked[$current['type']][$current['id']])) {
       // Load the current entity.
-      $entities = entity_load($this->entityType, array($this->entityId));
+      $entities = entity_load($current['type'], array($current['id']));
       $entity = reset($entities);
 
-      $this->dependencies = module_invoke_all('entity_dependencies', $entity, $this->entityType);
+      $this->dependencies = module_invoke_all('entity_dependencies', $entity, $current['type']);
       //$this->belongings = module_invoke_all('entity_belongings', $entity, $this->entityType);
 
       // Don't add dependencies that already were checked.
-      foreach ($this->dependencies as $entity_type => $dependencies) {
-        foreach ($dependencies as $key => $entity_id) {
-          if (isset($this->checked[$entity_type][$entity_id])) {
-            unset($this->dependencies[$entity_type][$key]);
-            // We need to flush empty dependency trees to avoid creation of empty iterators.
-            if (empty($this->dependencies[$entity_type])) {
-              unset($this->dependencies[$entity_type]);
-            }
+      foreach ($this->dependencies as $key => $dependency) {
+          if (($dependency['type'] == $current['type'] && $dependency['id'] == $current['id'])
+            || isset($this->checked[$dependency['type']][$dependency['id']])) {
+
+            unset($this->dependencies[$key]);
           }
           else {
-            $this->causes[$entity_type][$entity_id] = array(
-              'type' => $this->entityType,
-              'id' => $this->entityId,
-            );
+            $this->causes[$dependency['type']][$dependency['id']] = $current;
           }
-        }
       }
-      // TODO: Do the same for belongings.
 
       // Let other modules have their say.
-      drupal_alter('entity_dependencies', $this->dependencies, $entity, $this->entityType);
-      //drupal_alter('entity_belongings', $this->belongings, $entity, $this->entityType);
+      drupal_alter('entity_dependencies', $this->dependencies, $entity, $current['type']);
 
       // Now mark this as checked.
-      $this->checked[$this->entityType][$this->entityId] = TRUE;
+      $this->checked[$current['type']][$current['id']] = TRUE;
 
       if (!empty($this->dependencies)) {
         return TRUE;
@@ -164,23 +149,16 @@ class EntityDependencyIterator implements RecursiveIterator {
   public function getChildrenEntities() {
     $entities = array();
     $current = current($this->entities);
-    if (is_array($current)) {
-      $entities = $current;
-    }
-    if (!empty($this->dependencies) || !empty($this->belongings)) {
+
+    if (!empty($this->dependencies)) {
       $entities = $this->dependencies;
       // In an iterator, having children means that the current key itself
       // isn't a part of the entities. However, we need that entity.. So we add
       // the parent as a part of the entities. And since children always should
       // go first, we add the parent last.
-      //if (isset($this->checked[$this->entityType][$this->entityId])) {
-        $entities[$this->entityType][] = $this->entityId;
-      //}
+      $entities[] = array('id' => $current['id'], 'type' => $current['type']);
+
 
-      // TODO: Add belongings to the array.
-      //foreach ($this->belongings as $entity_type => $entity_id) {
-      //  $entities[$entity_type][] = $entity_id;
-      //}
     }
     return $entities;
   }
@@ -191,9 +169,7 @@ class EntityDependencyIterator implements RecursiveIterator {
    * @return EntityDependencyIterator
    */
   public function getChildren() {
-    $iterator = new EntityDependencyIterator($this->getChildrenEntities(), $this);
-    $iterator->entityType = $this->entityType;
-    return $iterator;
+    return new EntityDependencyIterator($this->getChildrenEntities(), $this);
   }
 
   /**
@@ -204,24 +180,21 @@ class EntityDependencyIterator implements RecursiveIterator {
    */
   public function current() {
     $current = current($this->entities);
-    if (is_array($current)) {
-      return $current;
-    }
     // Load the current entity.
-    $entities = entity_load($this->entityType, array($this->entityId));
+    $entities = entity_load($current['type'], array($current['id']));
     $entity = reset($entities);
     // Add necessary metadata to the entity.
     $cause = FALSE;
-    if (!empty($this->causes[$this->entityType][$this->entityId])) {
-      $cause = $this->causes[$this->entityType][$this->entityId]['type'] . '/' . $this->causes[$this->entityType][$this->entityId]['id'];
+    if (!empty($this->causes[$current['type']][$current['id']])) {
+      $cause = $this->causes[$current['type']][$current['id']]['type'] . '/' . $this->causes[$current['type']][$current['id']]['id'];
     }
     $entity->__metadata = array(
-      'type' => $this->entityType,
-      'uri' => $this->entityType . '/' . $this->entityId,
+      'type' => $current['type'],
+      'uri' => $current['type'] . '/' . $current['id'],
       'cause' => $cause,
     );
     // Now mark this as traversed.
-    $this->traversed[$this->entityType][$this->entityId] = TRUE;
+    $this->traversed[$current['type']][$current['id']] = TRUE;
     return $entity;
   }
 
@@ -238,12 +211,7 @@ class EntityDependencyIterator implements RecursiveIterator {
   public function next() {
     do {
       $current = next($this->entities);
-      // If reached the end of array, then exit.
-      if (!$current || is_array($current) || !isset($this->entityType)) {
-        break;
-      }
-      // We need to skip all already traversed elements.
-    } while (isset($this->traversed[$this->entityType][$current]));
+    } while (!empty($current) && isset($this->traversed[$current['type']][$current['id']]));
   }
 
   /**
@@ -260,12 +228,8 @@ class EntityDependencyIterator implements RecursiveIterator {
    */
   public function valid() {
     $current = current($this->entities);
-    if (!empty($current) && is_array($current)) {
-      $this->entityType = key($this->entities);
-      return TRUE;
-    }
-    elseif (!empty($current) && is_numeric($current) && isset($this->entityType) && !isset($this->traversed[$this->entityType][$current])) {
-      $this->entityId = $current;
+    if (!empty($current) && is_array($current) && isset($current['type']) && isset($current['id'])  && !isset($this->traversed[$current['type']][$current['id']])) {
+      $this->current = $current;
       return TRUE;
     }
     return FALSE;
diff --git a/sites/all/modules/entity_dependency/entity_dependency.core.inc b/sites/all/modules/entity_dependency/entity_dependency.core.inc
index 6e62f99..c9b106e 100644
--- a/sites/all/modules/entity_dependency/entity_dependency.core.inc
+++ b/sites/all/modules/entity_dependency/entity_dependency.core.inc
@@ -62,7 +74,7 @@ function taxonomy_entity_dependencies($entity, $entity_type) {
     $dependencies = array();
     $terms = taxonomy_get_parents($entity->tid);
     foreach ($terms as $tid => $term) {
-      $dependencies['taxonomy_term'][] = $tid;
+      $dependencies[] = array('type' => 'taxonomy_term', 'id' => $tid);
     }
     return $dependencies;
   }
@@ -84,11 +96,7 @@ function field_entity_dependencies($entity, $entity_type) {
       drupal_alter('field_entity_dependencies', $field_dependencies, $entity_type, $entity, $field, $instance, $langcode, $items);
 
       if (!empty($field_dependencies)) {
-        foreach ($field_dependencies as $entity_type => $entity_ids) {
-          foreach ($entity_ids as $entity_id) {
-            $dependencies[$entity_type][] = $entity_id;
-          }
-        }
+        $dependencies = array_merge_recursive($dependencies, $field_dependencies);
       }
     }
   }
diff --git a/sites/all/modules/entity_dependency/entity_dependency.module b/sites/all/modules/entity_dependency/entity_dependency.module
index 625fd4b..982d9ff 100644
--- a/sites/all/modules/entity_dependency/entity_dependency.module
+++ b/sites/all/modules/entity_dependency/entity_dependency.module
@@ -58,10 +58,7 @@ function entity_dependency_add(&$dependencies, $objects, $entity_type, $properti
         $value = $object[$property];
       }
       if (!empty($value) && !($entity_type == 'user' && ((int)$value == 0 || (int)$value == 1))) {
-        if (!isset($dependencies[$entity_type])) {
-          $dependencies[$entity_type] = array();
-        }
-        $dependencies[$entity_type][] = $value;
+        $dependencies[] = array('type' => $entity_type, 'id' => $value);
       }
     }
   }
diff --git a/sites/all/modules/entity_dependency/entity_dependency.test b/sites/all/modules/entity_dependency/entity_dependency.test
index 14af22a..334cd57 100644
--- a/sites/all/modules/entity_dependency/entity_dependency.test
+++ b/sites/all/modules/entity_dependency/entity_dependency.test
@@ -85,7 +85,8 @@ class EntityDependencyTestCase extends DrupalWebTestCase {
     // Add only the last node to the collection. What should come out of the
     // iterator should be all it's dependencies, and last the node it self.
     $this->entities = array(
-      'node' => array($node2->nid, $node3->nid),
+      array('id' => $node2->nid, 'type' => 'node'),
+      array('id' => $node3->nid, 'type' => 'node'),
     );
  
     $i = 0;
