             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

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

  [^PersistentHashSet paths
   distance-fn'
   ^Number k]
  (let [; Wrap distance function, so that it allows to compare the same paths.
        distance-fn (fn [a b] (if (= a b) 0 (distance-fn' a b)))
        ; Function for selecting initial medoids
        vj (fn [path]
             (mapsum (fn [i]
                       (/ (distance-fn path i)
