    "hunt-and-kill" maze-hunt-and-kill})
 
 #?(:clj
-   (defn synchronous-algorithm [alg-name]
-     (fn [grid]
-       (async/<!! ((algorithm-functions alg-name) grid nil))))
+   (defn synchronous-fn [func]
+     (fn [& opts]
+       (async/<!! (apply func opts))))
    )
 
-(defn algorithm-fn [name options]
-  ;; Commenting this out for now while restructuring the cljs version
-  ;(let [algorithm (synchronous-algorithm name)
-  ;      analyze-distances (fn [maze] (find-distances maze (:distances options)))
-  ;      analyze-path (fn [maze] (find-path maze (:path-to options)
-  ;                                         (analyze-distances maze)))
-  ;      analyze-longest-path (fn [maze]
-  ;                             (let [distances (find-distances maze [0 0])
-  ;                                   distances-from-farthest (find-distances maze (:max-coord distances))]
-  ;                               (find-path maze (:max-coord distances-from-farthest) distances-from-farthest)))
-  ;      analyze (cond
-  ;                (:longest options) analyze-longest-path
-  ;                (:path-to options) analyze-path
-  ;                (:distances options) analyze-distances
-  ;                :else (fn [_] {}))]
-  ;  (fn [grid]
-  ;    (let [maze (algorithm grid)
-  ;          analysis (analyze maze)]
-  ;      (g/grid-annotate-cells maze
-  ;                                {:label (g/xform-values util/base36 analysis)
-  ;                                 :color (g/xform-values #(util/color-cell (:max analysis) %) analysis)}))))
-)
+#?(:clj
+   (defn algorithm-fn [name options]
+     ;; Commenting this out for now while restructuring the cljs version
+     (let [algorithm (synchronous-fn (algorithm-functions name))
+           analyze-distances (fn [maze] ((synchronous-fn find-distances) maze (:distances options)))
+           analyze-path (fn [maze] (find-path maze (:path-to options)
+                                              (analyze-distances maze)))
+           analyze-longest-path (fn [maze]
+                                  (let [distances (find-distances maze [0 0])
+                                        distances-from-farthest (find-distances maze (:max-coord distances))]
+                                    (find-path maze (:max-coord distances-from-farthest) distances-from-farthest)))
+           analyze (cond
+                     (:longest options) analyze-longest-path
+                     (:path-to options) analyze-path
+                     (:distances options) analyze-distances
+                     :else (fn [_] {}))]
+       (fn [grid]
+         (let [maze (algorithm grid)
+               analysis (analyze maze)]
+           (g/grid-annotate-cells maze
+                                  {:label (g/xform-values util/base36 analysis)
+                                   :color (g/xform-values #(util/color-cell (:max analysis) %) analysis)}))))
+     )
+   )

      grid
      (g/link-cells grid cell (rand-nth neighbors)))))

(s/defn maze-binary-tree [grid :- g/Grid result-chan]
  (go-loop [grid (assoc grid :algorithm-name "binary-tree")
            [coord & coords] (g/grid-coords grid)]
    (if-not coord
      (do
        (when result-chan (async/close! result-chan))
        grid)
      (do
        (when (and result-chan (g/changed? grid))
          (async/>! result-chan grid))
        (recur (binary-tree-step (g/begin-step grid) coord) coords)))))

(defn sidewinder-end-run? [cell]
  (let [on-east-side? (not (:east cell))

        [(g/link-cells grid current-cell neighbor)
         neighbor]))))

(s/defn maze-hunt-and-kill
  ([grid :- g/Grid] (maze-hunt-and-kill grid nil))
  ([grid :- g/Grid result-chan]
    (go-loop [grid (assoc grid :algorithm-name "hunt-and-kill")
              current-coord (g/random-coord grid)]
             (when (and result-chan (g/changed? grid))
               (async/>! result-chan grid))
      (let [[new-grid next-coord] (hunt-and-kill-step (g/begin-step grid) current-coord)]
        (if-not next-coord
          (do
            (when result-chan (async/close! result-chan))
            new-grid)
          (recur new-grid next-coord))))))

(s/defn find-distances :- g/Distances
  ([grid :- g/Grid start :- g/CellPosition] (find-distances grid start nil))
  ([grid :- g/Grid
    start :- g/CellPosition
    result-chan]
    (go-loop [distances {start 0 :origin start :max 0}
              current start
              frontier #?(:clj PersistentQueue/EMPTY
                          :cljs #queue [])]
      ;(when result-chan
      ;  (async/>! result-chan distances))
      (let [cell (g/grid-cell grid current)
            current-distance (distances current)
            links (remove #(contains? distances %) (:links cell))
            next-frontier (apply conj frontier links)]
        (if (empty? next-frontier)
          (do
            (when result-chan (async/close! result-chan))
            (assoc distances :max current-distance :max-coord current))
          (recur (if (empty? links)
                   distances
                   ;; This is *super* clumsy, but has the desirable effect that
                   ;; we only animate when the max distance actually increases.
                   ;; That seems right to me, and makes for a very pleasing
                   ;; animation (not too slow, but you can still see what's
                   ;; going on, and it really gives the impression of a flood).
                   ;; I just need to figure out a better way of triggering that
                   ;; condition.
                   (let [new-distances (apply assoc distances :max (inc current-distance)
                                              (mapcat #(vector % (inc current-distance)) links))]
                     (when (and result-chan
                                (> (new-distances (peek next-frontier)) current-distance))
                       (async/>! result-chan new-distances))
                     new-distances))
                 (peek next-frontier)
                 (pop next-frontier)))))))

(s/defn find-path :- g/Distances
  [grid :- g/Grid
