Reducing memory and time to build centroids.