   (def last-acq this)
     (reset! (.state this) {:stop false :pause false :finished false})
     (let [out-queue (LinkedBlockingQueue. 10)
-          acq-thread (Thread. #(run-acquisition this settings out-queue cleanup?)
+          acq-thread (Thread. #(binding [state (.state this)]
+                                 (run-acquisition settings out-queue cleanup?))
                               "AcquisitionSequence2010 Thread (Clojure)")]
       (reset! (.state this)
               {:stop false

        (def acq-sequence acq-seq)
        (execute (mapcat #(make-event-fns % out-queue) acq-seq)))
      (catch Throwable t
             (ReportingUtils/showError t "Acquisition failed."))
      (finally
        (when cleanup?
          (cleanup))
        (.put out-queue TaggedImageQueue/POISON)))))

;; generic metadata


(defn stop []
  (when-let [acq-thread (:acq-thread (.state last-acq))]
    (.stop acq-thread)))

(defn drain-queue [blocking-queue]
  (future (loop [i 0]
            (let [obj (.take blocking-queue)]
              (when (zero? (mod i 100))
                (println i (core getRemainingImageCount)))
              (when (not= obj blocking-queue)
                (recur (inc i)))))))

(defn null-queue []
  (doto (LinkedBlockingQueue.)
    drain-queue))

