rewrite kmeans to allow other distance metrics