         processes-cycles  (gen-processes-cycles processes)]
     (loop [quantum 0
            remaining-processes processes-cycles]
-      (if (and (more-incomplete-processes? (scheduled-processes-parts @scheduled))
+      (if (and (more-incomplete-processes? @scheduled)
                (< quantum timeout))
         (do
           (progress-on-process! locks scheduled

       (filter #(= (:inst-type %) :lock))
       (map #(hash-map :lock-id (% :inst-id) :lock-idx (.indexOf instructions %)))))

(defn the-locks-inst-depends-on
  [instructions instruction]
  (let [the-inst-idx (.indexOf instructions instruction)]
    (->> (all-lock-indices instructions)
         (filter #(> the-inst-idx (:lock-idx %) ))
         (map :lock-id)
         (into []))))

(defn lock [locks process-id lock-id]
  (assoc locks lock-id {:locker process-id :locked true}))

  (assoc locks lock-id {:locker process-id :locked false}))

(defn is-locked? [process-id instructions locks instruction]
  (->> (locks-inst-depends-on instructions instruction)
       (some #(and (not= process-id ((get locks %) :locker))
                   ((get locks %) :locked)))))

