   [language-model spec depth total-depth
                        & {:keys [max-total-depth]
                           :or {max-total-depth max-total-depth}}]
+  (log/debug (str "lightning-bolt with depth:" depth " and spec:" (strip-refs spec)))
   (let [grammar (:grammar language-model)
         depth (if depth depth 0)
         ;; this is the relative depth; that is, the depth from the top of the current lightning bolt.
         ;; total-depth, on the other hand, is the depth all the way to the top of the entire
         ;; expression, which might involve several parent lightning bolts.
-        parents (shuffle (candidate-parents grammar spec))]
+        parents
+        (let [parents (shuffle (candidate-parents grammar spec))]
+          (log/debug (str "candidate-parents:" (string/join "," (map :rule parents))))
+          parents)]
     (let [lexical ;; 1. generate list of all phrases where the head child of each parent is a lexeme.
           (when (= false (get-in spec [:head :phrasal] false))
             (lazy-mapcat

               (log/debug (str "parent: " (:rule parent) " over lexical heads."))
               (let [lexicon (or (:lexicon (:generate language-model)) (:lexicon language-model))
                     subset (if-let [index-fn (:index-fn language-model)]
                              (index-fn (get-in parent [:head] :top))
                              (flatten (vals lexicon)))]
                 (let [result
                       (mapcat #(over/overh parent %)
                               (shuffle subset))]
                   (if (and (not (empty? subset)) (empty? result)
                            (> (count subset)

    (if (> max-total-depth 0)
      (let [prob (- 1.0 (/ (- max-total-depth depth)
                           max-total-depth))]
        (log/trace (str "P(c," depth ") = " prob " (c: probability of choosing lexemes rather than phrases given depth " depth ")"))
        (> (* 10 prob) (rand-int 10)))
      false)))

