   (let [node-data (extensions/read-node sync exhaust-node)
         state-bucket (extensions/bucket sync :peer-state)
         task-node (:task-node node-data)
-        n (n-peers sync state-bucket task-node #{:acking :active :waiting :sealing})
-        n-active (n-peers sync state-bucket task-node #{:active})
-        n-waiting (n-peers sync state-bucket task-node #{:waiting})
-        n-sealing (n-peers sync state-bucket task-node #{:sealing})
+        peers (n-peers sync task-node)
+        n (+ (:acking peers) (:active peers) (:waiting peers) (:sealing peers))
         state-path (extensions/resolve-node sync :peer-state (:id node-data))
         peer-state (:content (extensions/dereference sync state-path))
         same-task? (= (:task-node peer-state) task-node)
         complete? (task-complete? sync task-node)
-        state (if (and (>= n-waiting (dec n))
-                       (zero? n-sealing)
+        state (if (and (>= (:waiting peers) (dec n))
+                       (zero? (:sealing peers))
                        (= (:state peer-state) :active))
                 (assoc peer-state :state :sealing)
                 (assoc peer-state :state :waiting))]

        state-path (extensions/resolve-node sync :peer-state (:id node-data))
        peer-state (:content (extensions/dereference sync state-path))
        complete? (task-complete? sync (:task-node peer-state))
        n (n-peers sync (extensions/bucket sync :peer-state)
                   (:task-node peer-state) #{:acking :active})]
    (if (and (or (= (:state peer-state) :sealing)
                 (= (:state peer-state) :dead))
             (= (:task-node peer-state) (:task-node node-data)))

  (let [states (extensions/bucket sync :peer-state)]
    (filter
     (fn [task]
       (let [peers (n-peers sync task)]
         (>= (+ (:acking peers) (:active peers) (:sealing peers)) 1)))
     tasks)))

(defn next-inactive-task [sync job-node]
