finish k-means implementation