   [state {:keys [counts end] :as datamap}]
   (first (filter end (pick-words (counts state)))))
 
-(defn- words-to-states
-  "Takes a state and a collection of words, and maps it to the next set of
-  states."
-  [state words]
-  (map #(conj (vec (rest state)) %) words))
-
-(defn- gen-next-continuations
-  [{:keys [counts end] :as datamap} {:keys [depth queue state]}]
-  (->> (counts state)
-       (pick-words)
-       (words-to-states state)
-       (remove #(end (last %)))
-       (map #(hash-map :depth (inc depth)
-                       :queue (conj queue state)
-                       :state %1))))
-
-;; cont consists of: {:depth depth, :queue string, :state state}
-;;   Works for 2-3 tuples with caveats - many fewer viable paths, so drops to
-;; dive a lot more! Also - it has n too many words, where n is one less than
-;; the size of the tuple.
-(defn- dfs-cont
-  [{:keys [counts end] :as datamap} n continuations]
-  (if-let [{:keys [depth queue state] :as cont} (first continuations)]
-    (if (>= (+ depth (count state)) n)
-        (if-let [end-state (find-first-end state datamap)]
-          (conj queue state (vector end-state))
-          (recur datamap n (rest continuations)))
-        (if-let [new-conts (seq (gen-next-continuations datamap cont))]
-          (recur datamap n (apply conj (rest continuations) new-conts))
-          (recur datamap n (rest continuations))))))
-
-(defn gen-next-info
-  [{:keys [counts end] :as datamap} {:keys [depth node edges]}]
+(defn gen-next-frame
+  "Builds the next frame, applying the func parameter to the depth to produce
+  the next depth."
+  [inc-depth? 
+   {:keys [counts end] :as datamap} 
+   {:keys [depth node edges] :as frame}]
   (let [next-node (conj (vec (rest node)) (first edges))]
-    {:depth (inc depth)
+    {:depth (if inc-depth? (inc depth) depth)
      :node next-node
      :edges (pick-words (counts next-node))}))
 
-;; More true implementation of dfs
-(defn dfs-true
+(defn- dfs
+  "Runs a dfs to produce a sequence of tokens of n depth ending on a end node."
   [{:keys [counts end] :as datamap} n stack]
-  (Thread/sleep 500)
-  (prn (str "dfs-true first=" (first stack)))
   (if-let [{:keys [depth node edges] :as node-info} (first stack)]
     (cond
       (and (= (+ depth (dec (count node))) n) ; TODO: lol

                      (str %1 %2)
                      (str %1 \space %2))))))

(defn gen-sentence-true-dfs
  [{:keys [end] :as datamap} n]
  {:pre [(pos? n)]}
  (let [coll (if-let [s (dfs-true-begin datamap n)] s (dfs-single datamap n))]
    (->> coll
         (rest)
         (map last)
         (concat (first coll))
         (reduce #(if (end %2) 
                      (str %1 %2)
                      (str %1 \space %2))))))

(def map-loc "resources/public/corpora/loremipsum/2.json")
(use 'wysitutwyg.markov.textgen)
(def dmap (read-into-datamap map-loc))

;; TODO: Okay, it doesn't generate the currect length if you have 2-tuples.
;; I thought I fixed that, but I didn't.
;; This is why tests are good.

(defn sentence-length
  [s]
  (count (clojure.string/split s #"\s")))

;;; See: 85 - New - IS MULTIPLE SENTENCES!
(defn test-both [n]
  (let [old (binding [*rnd* (java.util.Random. 1)]
              (gen-sentence dmap n))
        new (binding [*rnd* (java.util.Random. 1)]
              (gen-sentence-true-dfs dmap n))]
    (do
      (if-not (= n (sentence-length old))
              (prn (str "OLD! N: " n " LEN: " (sentence-length old)
                        " SEN: " old)))
      (if-not (= n (sentence-length new))
              (prn (str "NEW! N: " n " LEN: " (sentence-length new)
                        " SEN: " new))))))

#_(doall (map test-both (range 1 100)))
;   Whoa okay, wow, some of this is super duper broken. Uh, is my end case
; HORRIBLY WRONG?

; -----=====##### CONCERNING NEW ALGORITHM GENNING SHORT #####=====-----
; Hmm, they all appear to be 1 off?
; No, they're not. See: #89, #87.
#_(doall (map test-both (range 30 50)))
#_(doall (map test-both (range 85 90)))

; -----=====##### CONCERNING #89 AND #50 #####=====-----
;   Okay, so, for #89 and #50 old, they both end on "resultant pleasure?" - 
; which is the last set of tokens in the corpus! So it has nowhere to go from
; there, since it's using 2-tuples, and so it goes woefully under-sized. That's
; because my dive doesn't do any backtracking. uuuuuuuuh why doesn't it do any
; backtracking? Past-me, I AM VERY CROSS.

; -----=====##### CONCERNING FALLBACK TEXT GENERATION BEHAVIOR #####=====-----
;   OKAY I get why some generated texts are slightly shorter than n! That's 

; text will be less than fifty words.
;   I will do the former.

;;; -----=====##### CONCERNING 153 #####=====-----
;   Watching what's happening using the true-dfs code is quite interesting. One
; thing that could be improved is predicting end branches. That is, if a node
