                    (flatten
                     (add-comps bolt-at model
                                comp-paths
-                               (mapfn #(comp-path-to-bolts bolt-at % model (+ 1 depth) max-depth)
+                               (mapfn #(comp-path-to-complements bolt-at % model (+ 1 depth) max-depth)
                                       comp-paths)
                                (+ 1 depth) max-depth top-bolt truncate? take-n)))))))
 (defn generate

  sequence of possible complements at the end of each such path. In
  addition, there is an key [] whose value is the bolt itself."
  [spec model depth max-depth]
  (map (fn [lb]
         (merge
          (let [comp-paths (find-comp-paths lb)]
            (zipmap comp-paths
                    (map (fn [path]
                           (filter not-fail? (comp-path-to-bolts lb path model depth max-depth)))
                         comp-paths)))
          {[]
           (filter not-fail? [lb])}))
       (lightning-bolts model spec depth max-depth)))

(defn comp-path-to-bolts
  "return a lazy sequence of bolts for all possible complements that can be added to the end of the _path_ within _bolt_."
  [bolt path model depth max-depth]
  (let [spec (get-in bolt path)
        lexemes (shufflefn (get-lexemes model spec))
        bolts-at (if (< depth max-depth)
                   (nugents
                    model
                    (get-in bolt path)
                    depth max-depth))
        lexemes-before-phrases
        (lexemes-before-phrases depth max-depth)]
    (if lexemes-before-phrases

                                        
;; during generation, will not decend deeper than this when creating a tree:
;; TODO: should also be possible to override per-language.
(def ^:const max-total-depth 2)

;; TODO support setting max-generated-complements to :unlimited
(def ^:const max-generated-complements 20000)
