 (def ^:const branch? #(let [result (= 0 (rand-int (+ % branching-factor)))]
                         (log/debug (str "branch at: " % "? => " result))
                         result))
+
+(def ^:dynamic default-fn (fn [x] [x]))
+(def ^:dynamic grammar)
+(def ^:dynamic index-fn nil)
+(def ^:dynamic lexicon)
+(def ^:dynamic morph-ps)
+(def ^:dynamic println? false)
 (def ^:dynamic truncate? false)
-(def ^:dynamic println? false)
-(def ^:dynamic default-fn (fn [x] [x]))
-(def ^:dynamic model)
-(def ^:dynamic morph-ps)
-(def ^:dynamic index-fn)
-(def ^:dynamic grammar)
 
 (declare assoc-children)
 (declare frontier)

(defn generate
  "Return one expression matching spec _spec_ given the model _model_."
  ([spec]
   (binding [model model
             morph-ps morph-ps
             grammar grammar
             index-fn index-fn]
     (first (gen spec))))

  ([spec model]
   (log/debug (str "(generate) with model named: " (:name model)
                   "; truncate? " truncate?))
   (binding [default-fn (:default-fn model)
             grammar (:grammar model)
             morph-ps (:morph-ps model)
             index-fn (if (:index-fn model)
                        (:index-fn model)
                        (do

                          (fn [spec]
                            (flatten (vals
                                      (or (:lexicon (:generate model))
                                          (:lexicon model)))))))
             morph-ps (:morph-ps model)]
     (first (gen spec)))))

(defn gen
