                  :soft-drop false
 
                  :quit false
-                 :quit-chan (chan)
 
                  :history []}))
+
+; This channel is closed when we want to shutdown all go-blocks
+; in order to exit the game.
+; It must be initialized to a new channel on init.
+(def quit-chan nil)
 
 ; required for pausing/resuming the gravity routine
 (def stop-grav (chan))

  (let [redraw-chan (make-redraw-chan)]
    (go
      (loop [board nil theme nil]
        (let [[_ c] (alts! [(:quit-chan @state) redraw-chan])]
          (if (= c redraw-chan)
            (let [new-board (drawable-board)
                  new-theme (:theme @state)

          (socket/emit "update-player" {:theme (:theme @state) :board (drawable-board)}))

        ; quit or schedule another update
        (let [quit quit-chan
              [_ ch] (alts! [quit (timeout 16)])]
          (when-not (= ch quit)
            (recur data)))))))
