 ;
 ; -----\----
 ;       \------
-;
-; [ . . . . . {new-branch: \ old-val: _ } . . . ] <
-;                           \                      \  
-;                            V                      \
-;                           {:offset-index _ :parent | :coll [ . . . .  ] }
+; [ . . . .  {:cont ---------------------> [ . . . . . ] 
+;             :branch | }]
+;                     \                        
+;                      V                      
+;                      [ . . . . . { . . }]
 
 (defn branch-at [i n]
   (prn "Branching at " i)
+  (swap! branch-count inc)
   (let [index i
-        new-branch {:offset-index i :coll (atom []) :parent (atom @current-branch)}
+        new-branch {:id (generate-uuid) :data (atom [])}
         ; split the current branch
-        coll @(@current-branch :coll)
-        [pre-branch post-branch] [(vec (take index coll)) (vec (drop index coll))]
+        data @(@current-branch :data)
+        [pre-branch post-branch] [(vec (take index data)) (vec (drop index data))]
         ; insert the branching point into the old branch
-        branched-branch (into [] (concat pre-branch [{:new-branch new-branch :old-value (first post-branch)}] (rest post-branch)))]
+        branched-branch (into [] (concat pre-branch [{:cont post-branch :branch new-branch}]))]
       ; update the old branch with the inserted version
-      (reset! (@current-branch :coll) branched-branch)
+      (reset! (@current-branch :data) branched-branch)
       ; let current branch pointer point to new branch
       (add-new-branch new-branch)
       (reset! reverted-to -1)))


(defn revert-to [i]
  (prn "request revert: " i)
  (let [index (* (dec (count @(@current-branch :coll))) (/ i 100))]
    (when-let [state (when (>= index 1) (nth-history index))]
      (prn "revert to: " index)
      (reset! app-state state)

      (branch-at @reverted-to n)
      ; else just append to history
      :else
      (let [b @(@current-branch :data)]
        (when-not (= (last b) n)
          (swap! (@current-branch :data) conj n))
        (let [c (len @(@current-branch :data))]
            (prn (str c " Saved " (pluralize c "State")))))))

; (om/root
;   (fn [app owner]
