fixing the distance search