First implementation of K-means