Added centroid algorithm