Adding distance calculation and sorting