Centroid calculation fix