Fix centroid calculation