     (when-not (empty? z-drive)
       (when (z-stage-needs-adjustment z-drive)
         (let [z (get-z-stage-position z-drive)]
-          (state-assoc! :reference-z z))))))
+          (swap! state assoc :reference-z z))))))
 
 ;; startup and shutdown
 

;; globals

(def ^:dynamic state (atom {:stop false}))

(defn state-assoc! [& args]
  (apply swap! state assoc args))

(def attached-runnables (atom (vec nil)))


  (try
    (attempt-all
      (log "cleanup")
      (swap! state assoc :finished true :display nil)
      (when (core isSequenceRunning)
        (core stopSequenceAcquisition))
      (stop-trigger)
