Implementing k-means from scratch