                      dense-grids->unique-clusters)]
     (init-clustering-iterations init-state 1)))
 
+(defn- step-nine! [current-cluster updated-state* pos-idx biggest-neighbor char-vec]
+  (if (= "NO_CLASS" current-cluster)
+    ;;step 10
+    (swap! updated-state* assoc-in [::grid-cells pos-idx]
+           (do
+             (log-it pos-idx ::move-grid-to-biggest-neighboring-cluster
+                     biggest-neighbor)
+             (assoc char-vec ::cluster biggest-neighbor)))
+    (swap! updated-state* assoc-in [::grid-cells]
+           (merge (::grid-cells @updated-state*)
+                  (if (> (cluster->size current-cluster @updated-state*)
+                         (cluster->size biggest-neighbor @updated-state*))
+                    ;;step 11
+                    (do
+                      (log-it pos-idx ::move-biggest-neighboring-cluster-to-current-cluster
+                              {:from biggest-neighbor
+                               :to   current-cluster})
+                      (relabel-cluster biggest-neighbor current-cluster @updated-state*))
+                    ;;step 12
+                    (do
+                      (log-it pos-idx ::move-current-cluster-to-biggest-neighboring-cluster
+                              {:from current-cluster
+                               :to   biggest-neighbor})
+                      (relabel-cluster current-cluster biggest-neighbor @updated-state*)))))))
+
+(defn- step-four! [char-vec pos-idx updated-state*]
+  (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*)]
+          ;;step 6
+          (when-not (is-grid-group new-cluster)
+            (do
+              (log-it pos-idx ::split-cluster new-cluster)
+              (split-cluster new-cluster))))))))
+
+(defn- step-fifteen! [current-cluster grid-w-biggest-neighbor updated-state* pos-idx char-vec biggest-neighbor]
+  (if
+    (and
+      (= "NO_CLASS" current-cluster)
+      (= ::outside (grid-is-inside-or-outside-group
+                     (first grid-w-biggest-neighbor)
+                     (keys
+                       (merge
+                         (cluster->grid-cells biggest-neighbor @updated-state*)
+                         {pos-idx char-vec})))))
+    (if (and (not (= "NO_CLASS" current-cluster))
+             (> (cluster->size current-cluster @updated-state*)
+                (cluster->size biggest-neighbor @updated-state*)))
+
+
+      (swap! updated-state* assoc-in [::grid-cells (first grid-w-biggest-neighbor)]
+             (do
+               (log-it pos-idx ::move-neighoring-grid-to-current-cluster
+                       {:from biggest-neighbor
+                        :to   current-cluster})
+               (assoc (second grid-w-biggest-neighbor) ::cluster current-cluster)))
+
+      )
+
+    ))
+
 (defn adjust-clustering [state t]
   (let [updated-state* (atom (update-grid-cells state t))]
     (doseq [[pos-idx char-vec] (::grid-cells @updated-state*)]


(defn pos-idxs->graph [position-indices]
  ;;TODO spec this
  (-> (into {}
            (map (fn [pos-idx]
                   [pos-idx (filter
                              (fn [ref-idx]
                                (and (not (= pos-idx ref-idx))
                                     (are-neighbors pos-idx ref-idx)))
                              position-indices)])
                 position-indices))
      (lgraph/graph)))

(defn is-grid-group
  "are all grids transitively neighbors?

    (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*))
                outside-grids  (filter
                                 (fn [[pos-idx char-vec]]
                                   (= ::outside
                                      (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*))]
                (doseq [neighbor neighbors]
                  (let [neighbor-cluster      (::cluster (second neighbor))
                        neighbor-cluster-size (cluster->size neighbor-cluster @the-state*)
