     (do (assert (pred (get m k) v)) m)
     (assoc m k v)))
 
-(defn merge-safe [pred & maps]
-  (apply merge-with (fn [x y] (assert (pred x y)) x) maps))
 
 
 (defn extract-effect [state context opt]

                                                      r])
                                         (concat new-results catchup)))
                           state reward-to-state) 
                         cut (val (first cutoff-depth-map))))   
        (let [[entry neg-reward] (queues/pq-remove-min-with-cost! 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  (println "found state" (map #(env/get-var b-s %) '[[atx] [aty]]) "for" (env/action-name (:action node)) "form" (map #(env/get-var state %) '[[atx] [aty]]) "with reward" b-rts "mcd" (:min-cycle-depth entry))
                (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 rcut] (if-let [stack-depth (.get stack-node-depths b-sa)]
                            (do ;(println "Stack hit on" (env/action-name (:action b-sa)) (map #(env/get-var b-s %) '[[atx] [aty]])) 
                                [(PartialResult {} Double/NEGATIVE_INFINITY stack-depth) (- neg-reward)])
                            [(expand-sa-node b-sa cache rec-next-best b-s b-rts (- 0 neg-reward b-rts)
                                              stack-node-depths (inc depth)) (+ (cutoff (:queue b-sa)) b-rts)])
                  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)]]                                 

                                                    (< (- good-pri) (:reward-to-state node)) :sbn
                                                    :else                                    :dbn)))
                                          bad-nodes)]
;              (println (apply str (repeat depth \ )) (count good-nodes) (count nbn) (count dbn) (count sbn))
              (reset! (:rec-context-atom entry) (:rec-context rec))
              (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)
