added support for arbitrary numbers of clusters in k-means