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

      ;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 add
  "adds a node with one child at each level(a limb) to the children of a node"
  ; TODO use a indexes func on a limb instead of this
  [{:keys [children triple] :as node}
   {-children :children -element :element -triple :triple
    :as limb}]
