added distance check during search