complete code for proximity check