added sort for distance