Added code to determine the clusterings like in the k-means function.