 
 (def state (atom (default-state)))
 
-(defn get-state [key]
-  (get-in @state [key]))
+(defn get-state
+  ([key & keys]
+     (map get-state (conj keys key)))
+  ([key]
+     (get-in @state [key])))
 
 (defn set-state!
   ([val-map]
      (swap! state merge val-map))
 
   ([key val]
-     (print key val)
      (swap! state assoc key val)))
 
 (defn set-time! [time]
   (set-state! (time-map time)))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Timer logic
+(def ^:constant time-speed 1e3)
+
+(def timer-chan
+  (let [c (chan)
+        timer (js/setInterval
+               #(when (get-state :on?) (put! c true))
+               time-speed)]
+    c))
+
+(go (while true
+      (<! timer-chan)
+      (when-not (apply expired? (get-state :stime :etime))
+        (set-state! :etime (dec-time (get-state :etime))))))
+
+(add-watch state :end
+           (fn [k r os ns]
+             (when (and (get-state :on?) (apply expired? (get-state :stime :etime)))
+               (play-sound)
+               (set-state! :on? false))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Generic Views

  "Creates a large button"
  ([body] (btn-lg {} body))

  ([{:keys [on-click]} & body]
     [:button {:class "btn btn-lg"
               :on-click on-click} body]))


    [btn-lg {:on-click on5} 5]
    [:br]
    ;; TODO togglify
    [btn-lg {:on-click on-toggle} [icon (if (get-state :on?) "pause" "play")]]
    [btn-lg {:on-click on-reset} [icon "refresh"]]]))

(defn timer-view []
