implemented distance check