                                           bad-nodes)]
               (doseq [n good-nodes]       (queues/g-pq-add! good-queue n (- (:reward-to-state n))))
               (doseq [n (concat nbn sbn)] (queues/g-pq-add! bad-queue  n (- (:reward-to-state n))))
+              (queues/pq-remove-min-with-cost! both-queue)
               (when (> (:cutoff rec) Double/NEGATIVE_INFINITY)
                 (queues/g-pq-replace! (if (< cd depth) bad-queue good-queue) entry (- 0 b-rts (:cutoff rec))))
               (recur new-results
-                     (extend-cutoff-depth-map cutoff-depth-map (:cutoff rec) cd)
+                     (extend-cutoff-depth-map cutoff-depth-map (:cutoff rec) cd depth)
                      (concat (when (and (>= b-cd depth) (< cd depth)) [entry])
                              (doall (for [n sbn] (queues/g-pq-remove! good-queue n)))
                              good-roots)))))))))
+
+;; Need same fix as regular since in cycles we may still check cutoff. 
 
 ;; ALMOST: except suboptimal states may get cached at higher levels too.
 ;; Such bad states cannot be cached.  

                                         (concat new-results catchup)))
                           state reward-to-state) 
                         cut (val (first cutoff-depth-map))))   
        (let [[entry neg-reward] (queues/g-pq-remove-min-with-cost! (:queue node))
              b-s (:state entry), b-rts (:reward-to-state entry), 
              b-ra (:remaining-actions entry), b-sa (:sanode entry), b-cd (:min-cycle-depth entry)
              rec-next-best (- (max next-best (cutoff both-queue)) b-rts)]
          (if (empty? b-ra)
              (recur (assoc-safe new-results >=
                       (vary-meta (extract-effect b-s (:context node) (:opt (meta b-s))) assoc :entry entry) b-rts)
                     cutoff-depth-map good-roots)
            (let [rec (if-let [stack-depth (.get stack-node-depths b-sa)]
                           (PartialResult {} Double/NEGATIVE_INFINITY stack-depth)
                         (expand-sa-node b-sa cache rec-next-best b-s b-rts (- 0 neg-reward b-rts)

            (queues/g-pq-replace! good-queue entry 
              (- 0 (:reward-to-state entry) (if-let [n  (:sanode entry)] (cutoff (:queue n)) 0))))
          (.remove stack-node-depths node) ;; TODO: catchup!! 
          (println "Returning from" (env/action-name (:action node)) "With cutoff" cut (cutoff good-queue) "and cdm" cutoff-depth-map "and states" (count new-results) (count catchup) "-" (count clean) (count dirtied) (count still-dirty) "and good roots" (count good-roots) (map :reward-to-state good-roots))
          (PartialResult (stitch-effect-map 
                           (into {} (map (fn [[s r]] [(vary-meta s assoc :cycle-depth 
                                                        (final-cycle-depth r (or (:cycle-depth (:entry (meta s))) 
