K-means code update