     (doseq [initial-cluster the-clusters]
       (let [grids-in-cluster (cluster->grid-cells initial-cluster @the-state*)]
         (doseq [grid-in-cluster grids-in-cluster]
-          (let [its-grid-group (grid-cell->grid-group (apply hash-map grid-in-cluster) (::grid-cells @the-state*))
+          (let [its-grid-group (grid-cell->grid-group (apply hash-map grid-in-cluster)
+                                                      (::grid-cells @the-state*))
                 outside-grids  (filter
                                  (fn [[pos-idx char-vec]]
                                    (= ::outside
-                                      (grid-is-inside-or-outside-group pos-idx (keys its-grid-group))))
+                                      (grid-is-inside-or-outside-group pos-idx
+                                                                       (keys its-grid-group))))
                                  its-grid-group)]
             (doseq [outside-grid outside-grids]
-              (let [neighbors (grid-cell->neighbors (apply hash-map outside-grid) (::grid-cells @the-state*))]
+              (let [neighbors (grid-cell->neighbors (apply hash-map outside-grid)
+                                                    (::grid-cells @the-state*))]
                 (doseq [neighbor neighbors]
                   (let [neighbor-cluster      (::cluster (second neighbor))
                         neighbor-cluster-size (cluster->size neighbor-cluster @the-state*)

      (when (= t (::last-time-label-changed char-vec))
        (do
          (log-it pos-idx ::label-changed-this-iteration char-vec)
          ;;4
          (when (= ::sparse (::label char-vec))
            (do
              (log-it pos-idx ::sparse-label char-vec)
              (let [old-cluster (::cluster char-vec)]
                (swap! updated-state* assoc-in [::grid-cells pos-idx]
                       (assoc char-vec ::cluster "NO_CLASS"))
                (let [new-cluster (cluster->grid-cells old-cluster @updated-state*)]
                  ;;6
                  (when-not (is-grid-group
                              new-cluster)
                    (do
                      (log-it pos-idx ::split-cluster new-cluster)
                      (split-cluster new-cluster)))))))
          ;;7
          (when (= ::dense (::label char-vec))
            (do (log-it pos-idx ::dense-label char-vec)
                (let [neighbors          (grid-cell->neighbors {pos-idx char-vec} (::grid-cells @updated-state*))
                      neighbors-clusters (->>
                                           (::grid-cells @updated-state*)
                                           (grid-cell->neighbors {pos-idx char-vec})
                                           vals
                                           (map ::cluster)
                                           (remove nil?)
                                           not-empty)]
                  (when neighbors-clusters
                    (let [cluster-sizes                      (map (fn [cluster]
                                                                    hash-map
                                                                    :cluster cluster
                                                                    :cluster-size (cluster->size cluster @updated-state*))
                                                                  neighbors-clusters)
                          biggest-neighboring-cluster        (->> cluster-sizes
                                                                  (sort-by :cluster-size)
                                                                  first
                                                                  :cluster)
                          grid-w-biggest-neighboring-cluster (first
                                                               (keep
                                                                 (fn [neigh-pos-id neigh-char-vec]
                                                                   (= biggest-neighboring-cluster
                                                                      (:cluster neigh-char-vec)))
                                                                 neighbors))
                          current-cluster                    (::cluster char-vec)]
                      (case (::label grid-w-biggest-neighboring-cluster)
                        ;;9
                        ::dense (
                                  ;;10
                                  (if (= "NO_CLASS" current-cluster)
                                    (swap! updated-state* assoc-in [::grid-cells pos-idx]
                                           (do
                                             (log-it pos-idx ::move-grid-to-biggest-neighboring-cluster biggest-neighboring-cluster)
                                             (assoc char-vec ::cluster biggest-neighboring-cluster)))
                                    (swap! updated-state* assoc-in [::grid-cells]
                                           (merge (::grid-cells @updated-state*)
                                                  (if (> (cluster->size current-cluster @updated-state*)
                                                         (cluster->size biggest-neighboring-cluster @updated-state*))
                                                    ;;11
                                                    (do
                                                      (log-it pos-idx ::move-biggest-neighboring-cluster-to-current-cluster {:from biggest-neighboring-cluster
                                                                                                                             :to   current-cluster})
                                                      (relabel-cluster biggest-neighboring-cluster current-cluster @updated-state*))
                                                    ;;12
                                                    (do
                                                      (log-it pos-idx ::move-current-cluster-to-biggest-neighboring-cluster {:from current-cluster
                                                                                                                             :to   biggest-neighboring-cluster})
                                                      (relabel-cluster current-cluster biggest-neighboring-cluster @updated-state*)))))))

                        ;;15
                        ::transitional ()
                        )

                      ))))))))))

(s/fdef initial-clustering
        :args (s/cat :u ::state :v ::t)

                      (when (= ::transitional (::label (second neighbor)))
                        (swap! the-state* assoc-in [::grid-cells]
                               (merge (::grid-cells @the-state*)
                                      {(first neighbor)
                                       (assoc (second neighbor) ::cluster initial-cluster)}))))))))))))
    @the-state*))

(defn- init-clustering-iterations [state iter-count]
