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

    (log-cmd (@state :last-wake-time))
    (when (pos? sleep-time)
      (Thread/sleep sleep-time)
      (dosync (alter state assoc :last-wake-time target-time)))))

(declare device-agents)


    (event-fn)))

(defn stop-acq []
  (swap! state assoc :stop true))
  
(defn pause-acq []
  (swap! state assoc :pause true))
  
(defn run-acquisition [settings out-queue] 
  (def acq-settings settings)
  (binding
    [state (atom {: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)
