kmeans refactor