         state (if (= (:frames-to-wait search-state) 1)
                 (x-first-search (assoc-in state [:search-state :frames-to-wait] frames-between-visits))
                 (update-in state [:search-state :frames-to-wait] dec))
-        collection (get-in state [:search-state :collection]) 
-        state (if (empty? collection) 
+        collection (get-in state [:search-state :collection])
+        state (if (empty? collection)
                 ;; when x-first-search returns empty collection, search finished, so start fresh with the other search alg
-                (infer-new-search-state (if (= :bfs (get-in state [:search-state :search-type])) :dfs :bfs) (:nodes state))
+                (merge state
+                       (infer-new-search-state (if (= :bfs (get-in state [:search-state :search-type])) :dfs :bfs) (:nodes state)))
                 state)]
     state))
 
 (defn update-state
   "quil update-state step"
   [state]
-  (update-colors 
-    (update-movement state)))
-
-(defn draw-state 
-  "quil draw-state step"
-  [state]
-  (q/background 0 0 0 0)
-  (q/no-stroke)
-  (let [nodes (:nodes state)
-        edges (extract-edges (vals nodes))
-        visiting (peek (get-in state [:search-state :collection]))] 
+  (-> state update-movement update-colors))
+
+(defn draw-edges [state]
+  (let [{:keys [nodes colors]} state
+        edges (extract-edges (vals nodes))]
     (q/fill (:edge colors)) ; set fill as edge color
     ;; draw each edge as a quad. Determine points using some mathematical math.
-    (doseq [ks edges]
-      (let [ks (into [] ks)
-            n1 ((nth ks 0) nodes)
-            n2 ((nth ks 1) nodes)
+    (doseq [edge edges]
+      (let [[n1 n2] (map nodes edge)
             n1-pos (:pos n1)
             n2-pos (:pos n2)
             x1 (:x n1-pos)

(defn adjust-directional-vel-to-bounds
  "adjust velocity if it is too fast or goes outside of view area"
  [vel pos max-speed min-pos max-pos bounce-vel size]
  (cond 
    (> (+ pos vel (/ size 2)) max-pos)
    (- 0 bounce-vel)


   :dfs '()})

;;;
;;; util
;;;

(defn rand-bi-dir
  "get a random value between -n and n"
  [n]
  (q/random (- n) n))

(defn map-value
  "iterates through map and applies fn to values returning new map"
  [fn m]
  (into {} (for [[key value] m] [key (fn value)])))

;;;
;;; graph elements and operations
;;;

(defn create-random-node
  "Construct a random node record
   label used for referencing the node in the graph's map"
  [label]
  {:label label
   :pos {:x (rand-int (q/width))
         :y (rand-int (q/height))}
   ; color key used by the x-first-search and as the key for physically coloring the node
   :color-key :untouched
   :size (+ size-min (rand-int (- size-max size-min)))
   :vel {:x (rand-bi-dir directional-speed-max)
         :y (rand-bi-dir directional-speed-max)
         :s (rand-bi-dir size-acceleration)}
   :siblings '()})

(defn add-edge
  "add an edge (set with two elements - the label of each node) to a node-map (map node-label->node)."
  [nodes edge]
  (let [[n1-label n2-label] edge]
    (-> nodes
        (update-in [n1-label :siblings] conj n2-label)
        (update-in [n2-label :siblings] conj n1-label))))

(defn extract-edges
  "get a set of edges given a node-map"
  [nodes]
  (set (for [node nodes
             sibling-label (:siblings node)]
         #{(:label node) sibling-label})))


;;;
;;; quil state manipulation and drawing
