added funtionality to checking the distance