moved sorting of vertices to function ...count_distances