kmeans base code + other changes