optimize centroid calculation - increase speed by almost 5x