added code for calculating centroid