refactored KMeans class