   (match message
 
     [[:display xy] :click _]
-    (if (= (:mode state) :formula)
-      
+    (case (:mode state)
+
+      :formula
       (let [formula (write-formula xy state)]
         [[(source-mode xy)
           (display-mode (:source state))
           [[:edit (:focus state)] :value formula]]
-         (assoc state
-           (:focus state)
-           formula :source xy)])
-      
+         (assoc state :source xy (:focus state) {:formula formula})])
+
       [[(edit-mode xy)
         (display-mode (:edit state))]
        (assoc state :edit xy)])

    [[] (assoc state :focus xy)]
    
    [[:edit xy] :focus? false]
    (if (= (:mode state) :formula)
      [[] state]
      [[(display-mode xy)
        [[:display xy] :value (cell-value (:focus state) state)]]
       (assoc state :mode :done)])

    [[:edit xy] :value v]
    (if (formula? v)
      [[(formula-mode xy)]
       (-> (assoc state :mode :formula)
           (assoc-in [:cells xy :formula] v))]
      [[] (-> (assoc state :mode :value)
              (assoc-in [:cells xy :value] v))])

    [[:edit xy] :key-down 13]
    [[(display-mode xy)

(def ops {"/" / "*" * "+" + "-" -})

(defn resolve-var [xy env]
  (get-in env [xy :value]))

(defn string->token [s env]
  (or (ops s)
