       (when (and (@state :init-continuous-focus)
                  (not (core isContinuousFocusEnabled)))
         (enable-continuous-focus true))
-      (when gui (.enableRoiButtons gui true)))
+      (when gui (.enableRoiButtons gui true))
+      (unsubscribe-state-from-core-callbacks state))
     (catch Throwable t 
            (ReportingUtils/showError t "Acquisition cleanup failed."))))
 

          (.enableRoiButtons false)))
      (prepare-state state (when (:use-position-list settings) position-list) autofocus-device)
      (def last-state state) ; for debugging
      (let [acq-seq (generate-acq-sequence settings @attached-runnables)]
        (def acq-sequence acq-seq) ; for debugging
        (execute (mapcat #(make-event-fns % out-queue) acq-seq)))

           :pixel-type (get-pixel-type)
           )))

(defn subscribe-state-to-core-callbacks
  "Subscribes the state to core callbacks."
  [state]
  (when gui
    (let [mm-listener
          (proxy [MMListenerAdapter] []
            (stagePositionChangedAlert [z-stage z]
              (swap! state assoc-in [:last-stage-positions z-stage] z))
            (xyStagePositionChanged [xy-stage x y]
              (swap! state assoc-in [:last-stage-positions xy-stage] [x y])))]
      (.addMMListener gui mm-listener)
      (alter-meta! state update-in [:mm-listeners] conj mm-listener))))

(defn unsubscribe-state-from-core-callbacks
  "Unsubscribes the state from any subscribed core callbacks."
  [state]
  (when gui
    (let [listeners (get-in (meta state) [:mm-listeners])]
      (doseq [listener listeners] (.removeMMListener gui listener)))
    (alter-meta! state assoc-in [:mm-listeners] nil)))

(defn cleanup []
  (try
    (attempt-all
