kmeans alg rearrangement