           ;; emit final completion barrier
           (periodic-barrier (assoc-in state [:job :sealing?] true))
 
-          (and (:scheduled? barrier) (> (System/nanoTime) next-barrier-time))
+          (and (:scheduled? barrier) (> (System/nanoTime) (:next-barrier-time barrier)))
           (periodic-barrier state)  
 
           (and (not (:scheduled? barrier))
-               (not (checkpointing? state status)))
+               (not (checkpointing? (:checkpoint state) status)))
           (-> state
-              (assoc-in [:barrier :scheduled?] true)
-              (assoc :next-barrier-time (+ (System/nanoTime) barrier-period-ns) 
-                     :checkpointing? false))
+              (update :barrier {:scheduled? true
+                                :next-barrier-time (+ (System/nanoTime) barrier-period-ns)})
+              (assoc-in [:checkpoint :initiated?] false))
 
           :else
           (do

        (assoc-in [:checkpoint :write-version] write-version)
        (assoc :last-heartbeat-time (System/nanoTime)))))

(defn checkpointing? [state status]
  (and ;; we've initiated a snapshot
       (:checkpointing? state)
       ;; none of the statuses are saying they're checkpointing
       (or (:checkpointing? status)
           ;; and they are all at least up to the checkpoint barrier
           ;; which means that we are not getting a stale status
           (< (:min-epoch status)
               (:epoch (:checkpoint state))))))

(defn coordinator-iteration 
  [{:keys [messenger last-heartbeat-time next-barrier-time allocation-ch shutdown-ch peer-config barrier job] :as state}
   coordinator-max-sleep-ns
   barrier-period-ns
   heartbeat-ns]
  (println "COORDINATOR ITERATION STATE" barrier job)
  (let [_ (run! pub/poll-heartbeats! (m/publishers messenger))
        status (merged-statuses messenger)
        {:keys [sealing? completed?]} job]
    (assert (not (nil? sealing?)))
    (assert (not (nil? completed?)))
    ;(println "COORDINATOR STATUS" status (m/replica-version messenger) (m/epoch messenger) :sealing? (:sealing? state))
    (cond (> (System/nanoTime) (+ last-heartbeat-time heartbeat-ns))
          ;; Immediately offer heartbeats
          (offer-heartbeats state)

          barrier-period-ns (ms->ns (arg-or-default :onyx.peer/coordinator-barrier-period-ms peer-config))
          heartbeat-ns (ms->ns (arg-or-default :onyx.peer/heartbeat-ms peer-config))
          result (loop [state (initialise-state state)]
                   (if-let [scheduler-event (poll! shutdown-ch)]
                     (do (shutdown (assoc state :scheduler-event scheduler-event))
                         :shutdown)
