 ;; Atoms
 ;;------------------------------------------------------------------------------
 
-(def snapshots (atom nil))
+(def snapshot-list (atom nil))
+(def snapshot-index (atom nil)) ; can this be derived from current time, quickly?
 (def selected-time (atom nil))
-(def url-update-timout (atom nil)) ; This probably doesn't need to be atom, maybe be clojure feature that handles this
+(def url-update-timeout (atom nil)) ; This probably doesn't need to be atom, maybe be clojure feature that handles this
 
 ;;------------------------------------------------------------------------------
 ;; Timepicker

    (val ($ "#hour") (pad hour))
    (val ($ "#minute") (pad (.getMinutes new-time)))
    (val ($ "#meridian") meridian)
    (.datepicker ($ "#datepicker") "update" new-time))
    )
; CONTINUE HERE - REWORKING snapshots, selected-time atom

  (let [snapshot (@snapshots new-index)
        time (Date. (:time snapshot))
        image (:image snapshot)
        time-display (str (.toDateString time) " " (.toLocaleTimeString time))]
    (attr ($ "#currentSnapshot") "src" image)
    (text ($ "#imageDateTime") time-display)
    (prop ($ "#earlier") "disabled" (= (inc new-index) (count @snapshot-list)))
    (prop ($ "#later") "disabled" (zero? new-index))))

(add-watch timestamp :_ on-selected-time-change)

;;------------------------------------------------------------------------------
;; Events

(defn set-minutes! [new-mins]
  (swap! selected-time doto (.setMinutes new-mins)))

(defn sync-time-with-snapshot! []
  (swap! selected-time #(js/Date. (:time @snapshot-index))))

; TODO: This could be improved. Probably need to rethink my data model
(defn show-closest-snapshot! []
  (let [timestamp (.getTime @selected-time)]
        earlier-index (keep-indexed #(if (>= timestamp (:time %2)) %1) @snapshot-list)
        later-index (dec earlier-index)
        later (:time (@snapshot-list later-index))
        earlier (:time (@snapshot-list earlier-index))
        display-index (if (< (- later timestamp) (- timestamp earlier))
                        later-index
                        earlier-index))
    (swap! selected-index #(display-index)))

(defn set-url! [timestamp]
  (let [base-url (.split js/document.URL "?")
        new-url (str base-url "?time=" timestamp)])
    (.replaceState js/history nil nil new-url))

;;------------------------------------------------------------------------------
;; Watchers
;;------------------------------------------------------------------------------

(defn on-selected-time-change [_ _ _ new-time]
  (let [hour (.getHours new-time)
        meridian (if (> 11 hour) "PM" "AM")
