reimplimented centroid func