Fixed bug with distance detection.