first version to sort by distance