Improved centroid calculation.