tweaked the distance detection