                           new-results)]
           (swap! (:result-map-atom node) (partial merge-safe >=) (into {} clean))
           (doseq [entry (concat good-roots (map #(:entry (meta (key %))) dirtied))] 
+            (assert (util/xor (not (:sanode entry)) (:cutoff (meta entry))))
             (queues/g-pq-replace! good-queue entry 
-              (- 0 (:reward-to-state entry) (if-let [n  (:sanode entry)] (cutoff (:queue n)) 0))))
+              (or (:cutoff (meta entry)) (- (: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))
+          (println "Returning from" (env/action-name (:action node)) (map #(env/get-var state %) '[[atx] [aty]]) "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))) 

                                         (concat new-results catchup)))
                           state reward-to-state) 
                         cut (val (first cutoff-depth-map))))   
        (let [[entry neg-reward] (queues/pq-peek-min both-queue)
              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)
              (do (queues/pq-remove-min-with-cost! both-queue) 
               (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)
                                         stack-node-depths (inc depth)))
                  cd  (min b-cd (:min-cycle-depth rec))
                  result-nodes (for [[ss sr] (:result-map rec)
                                     :let [s-cd (min (:cycle-depth (meta ss)) b-cd)]]                                 

(defn expand-sa-node [node #^HashMap cache next-best state reward-to-state last-cutoff
                      #^IdentityHashMap stack-node-depths depth]
  (assert (not (.containsKey stack-node-depths node)))
  (println "Entering " (env/action-name (:action node)) (map #(env/get-var state %) '[[atx] [aty]]) "at depth" depth ", " (count @(:result-map-atom node)) ", " last-cutoff reward-to-state)
  (.put stack-node-depths node depth)
  (let [good-queue (:queue node)
        bad-queue  (queues/make-graph-stack-pq)
