 (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)) "at depth" depth)
+  (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)

                          new-results)]
          (swap! (:result-map-atom node) (partial merge-safe >=) (into {} clean))
          (doseq [entry (concat good-roots (map #(:entry (meta (key %))) dirtied))] 
            (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))) 

                                          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))))
              (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 depth)
                     (concat (when (and (>= b-cd depth) (< cd depth)) [(vary-meta entry assoc :cutoff rcut)])
                             (doall (for [n sbn] (queues/g-pq-remove! good-queue n)))
                             good-roots)))))))))

;; TODO: Now, problem is that when we look at cutoff of good-root directly we miss cached states we haven't seen.!

;; ALMOST: except suboptimal states may get cached at higher levels too.
;; Such bad states cannot be cached.  
