         initial-clusters (into {}
                                (map (comp #(vector % #{}) first)
                                     (take k (sort-by second (map (juxt identity vj) paths)))))
-        ; Path is assigned to the medoid it is closest to. 
+        ; Path is assigned to the medoid it is closest to.
         assign-to-cluster (fn [clusters path]
                             (update clusters
                                     (reduce (partial min-key (partial distance-fn path)) (keys clusters))

                          (cond ; If the cluster is empty, return its medoid.
                                (empty? members) medoid
                                ; If there is 1 member in the cluster, return the member.
                                (= (count members) 1) (first members) 
                                ; 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
                              initial-clusters
                              (difference paths (set (keys initial-clusters))))))]
    (loop [clusters (reduce assign-to-cluster
                            initial-clusters
                            (difference paths (set (keys initial-clusters))))]
      (let [new-clusters (recluster clusters)
            distance-sum (sum-distances clusters)
            new-distance-sum (sum-distances new-clusters)]
        (if (= distance-sum new-distance-sum)
          (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
  [k ids distance-function]

                        (mapsum (fn [[medoid members]]
                                  (mapsum (partial distance-fn medoid) members))
                                clusters))
        ; Compute the total of distances between the members of a cluster.
        total-distance (fn [cluster member]
                         (mapsum (partial distance-fn member) cluster))
        ; Find new medoid from members of a cluster.
