 (defrecord SaveUndoEntry [id]
   ptk/UpdateEvent
   (update [_ state]
-    (let [page (udp/pack-page state id)]
+    (let [page (udp/pack-page state id)
+          undo {:data (:data page)
+                :metadata (:metadata page)}]
       (-> state
-          (update-in [:undo id :stack] #(cons (:data page) %))
+          (update-in [:undo id :stack] #(cons undo %))
           (assoc-in [:undo id :selected] 0)))))
 
-  ;; ptk/EffectEvent
-  ;; (effect [_ state]
-  ;;   (let [undo (get-in state [:undo id])]
-  ;;     (println (pr-str undo)))))
 
 (defn save-undo-entry
   [id]

  ptk/UpdateEvent
  (update [_ state]
    (let [page-id (get-in state [:workspace :page])
          undo (get-in state [:undo page-id])
          stack (:stack undo)
          selected (:selected undo)]
      (if (or (nil? selected) (zero? selected))
        state
        (let [pointer (dec selected)
              data (nth stack pointer)
              page (get-in state [:pages page-id])
              packed (assoc page :data data)]

          ;; (println "Redo: pointer=" pointer)
          ;; (println "Redo: packed=")

  ptk/UpdateEvent
  (update [_ state]
    (let [page-id (get-in state [:workspace :page])
          undo-state (get-in state [:undo page-id])
          stack (:stack undo-state)
          selected (:selected undo-state 0)]
      (if (>= selected (dec (count stack)))
        state
        (let [pointer (inc selected)
              page (get-in state [:pages page-id])
              undo (nth stack pointer)
              data (:data undo)
              metadata (:metadata undo)
              packed (assoc page :data data :metadata metadata)]

          ;; (println "Undo: pointer=" pointer)
          ;; (println "Undo: packed=")
