             distance-sum (sum-distances clusters)
             new-distance-sum (sum-distances new-clusters)]
         (if (= distance-sum new-distance-sum)
-          (keys clusters)
+          (keys clusters) ; If the total distance stays the same, return the medoids. 
           (recur (if (> distance-sum new-distance-sum) new-clusters clusters)))))))
 
 (defn k-medoids-initialization

        initial-clusters (into {}
                               (map (comp #(vector % #{}) first)
                                    (take k (sort-by second (map (juxt identity vj) paths)))))
        assign-to-cluster (fn [clusters path]
                            (update clusters
                                    (reduce (partial min-key (partial distance-fn path)) (keys clusters))
                                    conj
                                    path))
        sum-distances (fn [clusters]
                        (mapsum (fn [[medoid members]]
                                  (mapsum (partial distance-fn medoid) members))
                                clusters))
        total-distance (fn [cluster member]
                         (mapsum (partial distance-fn member) cluster))
        find-new-medoid (fn [[medoid members]]
                          (cond ; If the cluster is empty, return its medoid.
                                (empty? members) medoid

                                ; Otherwise select the members with the minimum total distance to the others
                                :else (apply min-key (partial total-distance members) members)))
        recluster (fn [clusters]
                    (let [initial-clusters (into {} (map (comp #(vector % #{}) find-new-medoid)
                                                         clusters))]
                      (reduce assign-to-cluster
