 (defn test-winner
   [owner current-field]
   (let [state (swap! app-state (partial change-ownership owner current-field))
-        winner (find-winner (:board state))]
+        winner (find-winner (:board state))
+        mark-fn (partial match-answer true)]
     (when winner
-      (do (swap! app-state #(assoc % :winner winner))
-          (set! (.-location js/window) "/#end")))))
+      (go (swap! app-state (comp mark-fn #(assoc % :winner winner)))
+          (<! (timeout verdict-display-time))
+          (swap! app-state (comp clear-answer deselect-current-field unmatch-answer))
+          (redirect "#end")))))
 
 (defn turn
   [& {:keys [answer answer-matched? correct-answer]}]
-  (let [mark-fn (partial match-answer answer-matched?)]
+  (let [mark-fn (partial match-answer answer-matched?)
+        keypresses (listen js/window.document "keydown")]
     (go (swap! app-state mark-fn)
-        (<! (timeout 3000))
+        (alts! [keypresses (timeout verdict-display-time)])
+        (close! keypresses)
         (swap! app-state (comp restart-timer toggle-player clear-answer
                                deselect-current-field unmatch-answer))))) 
 

  (:require [db-quiz.state :refer [app-state]]
            [db-quiz.config :refer [config]]
            [db-quiz.normalize :refer [replace-diacritics]]
            [cljs.core.async :refer [timeout]]
            [clojure.string :as string]
            [clojure.set :refer [intersection union]]
            [clj-fuzzy.jaro-winkler :refer [jaro-winkler]]))

(defn change-ownership
  [ownership field-id app-state]

                                                (fn [app-state] (assoc app-state :current-field id))))
                :missed (do (test-winner on-turn id)
                            (swap! app-state (comp toggle-player 
                                                   deselect-current-field)))
                nil))))

(defonce timeout-updater
  (js/setInterval (fn []
