refactored new kmeans (tested)