             (recur tail
                    (nth children head)
                    (+ acc (left-to-right head node)))
-            (dec acc)))) ;zero-based index
-      nil))
+            (dec acc))))))) ;zero-based index
 
 (defn indexes
   "returns a vector of numbers for each level that the index of a limb is
-  located at in a node"
+  located at in a node. returns nil instead of a number when it can't find the
+  limb (eg [1 2 3 nil])"
   [node limb]
   (loop [path [], node node, limb limb]
     (let [{:keys [children]} node

      ;does the node contain the limb
      (if (or (< index 0)
              (and (= index 0) (= (count children) 0)))
        nil
        ;does the limb have more children
        (if (or (= (count (:children limb)) 0)
                (= (count children) 0))

(defn index-of
  "returns the zero-based index of a limb in a node"
  [node limb]
  (let [paths (indexes node limb)]
    (if (some nil? paths)
      nil
      (loop [paths paths,
             node node,
             acc (if (:element node) 1 0)]
