Refactored KMeans and its tests