added sort group by distance functionality