centroid algorithm completed with results