implementing k-means algorithm