diff --git a/delete_orphaned_terms.module b/delete_orphaned_terms.module
index 4468e13..61775b0 100644
--- a/delete_orphaned_terms.module
+++ b/delete_orphaned_terms.module
@@ -99,26 +99,43 @@ function _dot_get($var) {
 }
 
 /**
- * Get count of vocabularies that are a tag based field on some content type (bundle).
- *
- * replacement for taxonomy_term_count_nodes()
+ * Replacement for taxonomy_term_count_nodes().
+ * @param tid
+ *   Term ID
+ * @param child_count
+ *   TRUE - Also count all nodes in child terms (if they exists) - Default
+ *   FALSE - Count only nodes related to Term ID
  */
-function __delete_orphaned_terms_tax_term_count_entities($tid, $count = TRUE) {
-  $cnt = 0;
+function _delete_orphaned_terms_node_count($tid, $child_count = TRUE) {
+  $tids = array($tid);
+  if ($child_count) {
+    $tids = array_merge($tids, _delete_orphaned_terms_get_children_ids($tid));
+  }
+  $query = db_select('taxonomy_index', 't');
+  $query->condition('tid', $tids, 'IN');
+  $query->join('node', 'n', 't.nid = n.nid');
+  $count = $query->countQuery()->execute()->fetchField();
+  return  $count;
+}
 
-  $instances = field_read_instances();
-  foreach ($instances as $instance) {
-    // check if this has to do with taxonomy, otherwise there will be no 'tid' column
-    if ($instance['widget']['module'] == 'taxonomy') {
-      $field = field_info_field_by_id($instance['field_id']);
-      $query = new EntityFieldQuery();
-      $query->fieldCondition($field, 'tid', $tid)
-        ->count();
-      $cnt += $query->execute();
+/**
+ * Retrieve ids of term children.
+ *
+ * @param $tid
+ *   The term's ID.
+ * @param $tids
+ *   An array where ids of term children will be added
+ */
+function _delete_orphaned_terms_get_children_ids($tid) {
+  $children = taxonomy_get_children($tid);
+  $tids = array();
+  if (!empty($children)) {
+    foreach ($children as $child) {
+      $tids[] = $child->tid;
+      $tids = array_merge($tids, term_get_children_ids($child->tid));
     }
   }
-
-  return $cnt;
+  return $tids;
 }
 
 /**
@@ -275,31 +292,31 @@ function _delete_orphaned_terms($form, $form_state) {
     $del_term = 0;
     $prune_local = array();
     foreach ($terms as $term) {
-      if (__delete_orphaned_terms_tax_term_count_entities($term->tid) <= $thres) {
+      if (_delete_orphaned_terms_node_count($term->tid) <= $thres) {
         $simulated_deletions = delete_orphaned_terms_simulate_delete($term->tid);
         $del_term = $del_term + count($simulated_deletions);
         foreach ($simulated_deletions as $simulated_deletion) {
           // PHP arrays are really hash tables which can be used to guarantee uniqueness for their keys
           $prune_local[$simulated_deletion] = $simulated_deletion;
         }
-      }
-    }
-    foreach ($terms as $term) {
-      if (in_array(($term->tid), $prune_local)) {
-        if ($state['sim']) {
-          drupal_set_message(t('Would delete term #@tid: @name (@vname)', array('@tid' => $term->tid,
+
+        if (in_array(($term->tid), $prune_local)) {
+          if ($state['sim']) {
+            drupal_set_message(t('Would delete term #@tid: @name (@vname)', array('@tid' => $term->tid,
+                                                                                  '@name' => $term->name,
+                                                                                  '@vname' => $vocab->name)));
+          }
+          else {
+            if (!$state['cron']) {
+              drupal_set_message(t('Deleting term #@tid: @name (@vname)', array('@tid' => $term->tid,
                                                                                 '@name' => $term->name,
                                                                                 '@vname' => $vocab->name)));
+            }
+          }    
         }
-        else {
-          if (!$state['cron']) {
-            drupal_set_message(t('Deleting term #@tid: @name (@vname)', array('@tid' => $term->tid,
-                                                                              '@name' => $term->name,
-                                                                              '@vname' => $vocab->name)));
-          }
-        }    
+
       }
-    }    
+    }
     
     // issue an error to the log if the configured failsafe (any) is out of bounds
     if (count($terms) > 0 && count($prune)/count($terms)*100 > _dot_get('delete_orphaned_terms_failsafe')) {
