Performance tweak for kmeans