distance calc -sorting complete