   (.indexOf xs n))
 
 (defrecord Node [triple element sub-counter children])
+
+(declare count-elements count-children filled-node make-node)
+
+(defn node-zip
+  [root]
+  (z/zipper :children (comp seq :children) make-node root))
+
+(defn node
+  [[triple & xs] element]
+  (if (= (count xs) 0)
+    (Node. triple element 0 [])
+    (Node. triple nil 1 [(node xs element)])))
+
+(declare add del fetch index-of indexes)
+
+(declare nth-child replace-node merge-node)
+
+(defn add
+  "adds a node with one child at each level(a limb) to the children of a node"
+  [node limb]
+  (let [paths (indexes node limb)
+        node-loc (node-zip node)]
+    (if (last paths)
+      (replace-node paths node-loc limb)
+      (merge-node paths node-loc limb))))
+
+(defn del
+  [node limb]
+  (let [paths (indexes node limb)]
+    (if (last paths)
+      (loop [[head & tail] paths
+             node-loc (nth-child (node-zip node) head)]
+        (if (empty? tail)
+          (-> node-loc
+              (z/edit assoc :element nil)
+              z/root)
+          (recur tail (nth-child node-loc head))))
+      node)))
+
+(declare left-to-right)
+
+(defn index-of
+  "returns the zero-based index of a limb in a node"
+  [node limb]
+  (let [paths (indexes node limb)]
+    (if (last paths)
+      (loop [[head & tail] paths,
+             {:keys [children] :as node} node,
+             acc (if (:element node) 1 0)]
+        (if head
+          (recur tail
+                 (nth children head)
+                 (+ acc (left-to-right head node)))
+          (dec acc)))
+      nil))) ;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. 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
+          index (find-in (map :triple children) (:triple limb))]
+      ;does the node contain the limb
+      (if (or (< index 0)
+              (and (= index 0) (= (count children) 0)))
+        (conj path nil)
+        ;does the limb have more children
+        (if (or (= (count (:children limb)) 0)
+                (= (count children) 0))
+          (conj path index)
+          (recur (conj path index)
+                 (nth children index)
+                 (first (:children limb))))))))
+
+(declare crawl-to crawl-out)
+
+(defn fetch [node index]
+  "takes a node and an index and returns a recreation of the node at that index
+  as a limb"
+  (-> node
+      (crawl-to index)
+      (crawl-out)))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Helpers
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defn count-elements
   [{:keys [sub-counter element]}]

        (recur (z/up zip) child)
        build))))

(defn fetch [node index]
  "takes a node and an index and returns a recreation of the node at that index
  as a limb"
  (-> node
      (crawl-to index)
      (crawl-out)))


           (nth-child node-loc head)
           (first (:children limb)))))

(defn left-to-right
  "a strategy that returns the sum of the branches to the left of a position
  in a node"
