Changed to a more straightforward calculation of the centroid.