     (log-cmd (@state :last-wake-time))
     (when (pos? sleep-time)
       (Thread/sleep sleep-time)
-      (dosync (alter state assoc :last-wake-time target-time)))))
+      (swap! state assoc :last-wake-time target-time))))
 
 (declare device-agents)
 

    (event-fn)))

(defn stop-acq []
  (dosync (alter state assoc :stop true)))
  
(defn pause-acq []
  (dosync (alter state assoc :pause true)))
  
(defn run-acquisition [settings out-queue] 
  (def acq-settings settings)
  (binding
    [state (ref {:pause false
                 :stop false
                 :z-corrections nil
                 :last-wake-time (clock-ms)
                 :start-time (clock-ms)
                 :init-auto-shutter (core getAutoShutter)
                 :last-z-position (get-z-stage-position (core getFocusDevice))})]
    (let [acq-seq (generate-acq-sequence settings)]
       (def acq-sequence acq-seq)
       (def last-state state)

    (.put out-queue (annotate-image image event))))
  
(defn store-z-correction [z event]
  (swap! state assoc-in [:z-corrections (get-in event [:position :label])] z))
 
(defn compute-z-position [event]
  (if-let [z-drive (:z-drive event)]
