         (connect-and-watch! ret (stub-f o) #(add-sp-child! ret %))
         (summaries/summary-changed! ret))) ;; TODO: efficiency?
     
-    ret))
+    (output-wrap ret)))
 
 
 

                 (let [left-done? (atom false)]
                   (fn [s b] 
                     (when (and (not @left-done?) (not (summary/live? (summaries/summary left-sp))))
                       (reset! left-done? true) (println "BOO")
                       (summaries/disconnect! s ss)
                       (add-watcher! left-sp (fn [o] (def *sum* [s left-sp o]) (throw (RuntimeException. "Solved and children."))))
                       (add-sp-child! s (make-nt-pair-subproblem subsuming-sp pair-stub left-sp right-sp)))
                     (or-summary s b))))             
             (fn [s ri] (make-pair-stub1 s (refine-input left-sp ri)
                          (subproblem-name right-sp) #(refine-input right-sp %)))

    (when subsuming-sp (summaries/connect! @ts-atom (tree-summarizer subsuming-sp) true))
    ret))

;; TODO: better grouping -- allow adding etc? 
(defn make-output-collecting-subproblem [inner-sp]
  (let [ts  (tree-summarizer inner-sp)
        ret (traits/reify-traits [simple-cached-node simple-watched ]
             summaries/Summarizable (summarize       [s] (or-summary s (top-down-bound ts)))
             Subproblem             (stub            [s] (stub inner-sp))
                                    (output-set      [s] (output-set inner-sp))
                                    (tree-summarizer [s] ts)
                                    (terminal?       [s] false)
                                    (refine-input    [s ni] (refine-input inner-sp ni)))
        child-watch (fn child-watch [o]
                      (if (= (output-set inner-sp) (output-set o))
                        (do (connect-and-watch! ret o child-watch)
                            (summaries/summary-changed! ret))
                        (add-sp-child! ret o)))]
    (connect-and-watch! ret inner-sp child-watch)    
    ret))

(defn output-wrap [sp]
  (if *no-identical-nonterminal-outputs*
    (make-output-collecting-subproblem sp)
    sp))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;     Subproblem Types and Stubs     ;;;;;;;;;;;;;;;;;;;;;;;
