added centroid distances calculation logic