       (push-to-tree-atom!  new-tree
                            tree-atom)
       new-tree)
-    (let [parent (produce-recent-tree-atom! (path-parents path)
+    (let [parent (produce-recent-tree-atom! (find-closest-parent path
+                                                                 path-parents)
                                             path-parents
                                             tree-atom)
           new-tree (-> (trace/mk-tree :parent @parent)

         conj
         node-atom))

(defn mk-recent-tree-at-inner-path
  [path path-parents tree-atom]
  (if (= (count path) 1) ;; TODO is this the right way to detect root?

  (or (meta form)
      (-> form first meta)))

(defn tr-loop-bind
  [template tree-atom v bnd-frm val-frm]
  (-> (produce-recent-tree-atom! (:inner-path template)
                                 (:path-parents template)
                                 tree-atom)
      deref
      (update-in [:let-binds] conj [v bnd-frm val-frm])
      (update-tree! tree-atom))
  v)

(defn xpand-loop-binds
  [xbinds orig-binds path-sym]
  (vec (mapcat (fn [[xb xv] [ob ov]]
                 `(~ob (tr-loop-bind ~path-sym
                                    ~'$$
                                    ~xv
                                    '~ob
                                    '~ov)))
               (partition 2 xbinds)
               (partition 2 orig-binds))))

(defn tr-loop
  [template tree-atom v]
  (-> (produce-recent-tree-atom! (:inner-path template)
