             (let [z (compute-z-position event)]
               (when (not= z (@state :last-z-position))
                 (do (set-stage-position z-drive z)
-                    (core waitForDevice z-drive)))))
+                    (wait-for-device z-drive)))))
           #(do (expose event)
                (collect-image event out-queue))))))
 

  (with-core-setting [getAutoShutter setAutoShutter false]
    (if open-before
      (core setShutterOpen true)
      (core waitForDevice (core getShutterDevice)))
    (core snapImage)
    (if close-after
      (core setShutterOpen false))
      (core waitForDevice (core getShutterDevice))))

(defn init-burst [length]
  (core setAutoShutter (@state :init-auto-shutter))


(declare device-agents)

(defn wait-for-device [dev]
  (when (and dev (pos? (.length dev)))
    (core waitForDevice dev)))

(defn create-device-agents []
  (def device-agents
    (let [devs (seq (core getLoadedDevices))]
