added in the implementation of sorting for proximity