Refactor kmeans (remove dependency on Devectorize)