changed  if statement to while for distance  above 500m
adding a comment to distance above 500