diff --git a/weblinks.module b/weblinks.module
index 6d77231..64e0eb9 100644
--- a/weblinks.module
+++ b/weblinks.module
@@ -1053,13 +1053,19 @@ function weblinks_get_tree($parent = 0, $quick = FALSE, $ismainlinkspage = TRUE)
   if ($parent) {
     // The existing elements have depths one too low.
     foreach ($tree as $term) {
+      // Increase the depth of each term by 1, so that we can insert the
+      // requested parent at depth 0 afterwards.
       ++$term->depth;
     }
     // Not top level, so we need to get the requested term
     // and stick it on the front of the tree.
     $parent_term = taxonomy_term_load($parent);
+    // Put parent term at top of array and set depth to 0.
     array_unshift($tree, $parent_term);
     $tree[0]->depth = 0;
+    // Remove 'parents' as this is not returned by the core taxonomy_term_load()
+    // but may be added by other modules hook_taxonomy_term_load()
+    unset($tree[0]->parents);
   }
   else {
     // Top level, so do we have unclassified links?
@@ -1107,12 +1113,12 @@ function weblinks_get_tree($parent = 0, $quick = FALSE, $ismainlinkspage = TRUE)
 
     $new_tree[$tid] = $term;
     $new_tree[$tid]->children = array();
+    // Use the data about the current term's parents ($term->parents) to
+    // populate the 'children' array for that parent object.
     if (isset($term->parents)) {
-      if ($term->parents[0] != 0) {
-        foreach ($term->parents as $parent) {
-          if (isset($new_tree[$parent])) {
-            $new_tree[$parent]->children[] = $tid;
-          }
+      foreach ($term->parents as $tid_parent) {
+        if (isset($new_tree[$tid_parent]) && $tid_parent != 0) {
+          $new_tree[$tid_parent]->children[] = $tid;
         }
       }
     }
