moved the core of the k-means algorithm to the 'kmeans' function