Formatted code, uncommented getToNearestIntersection and modified it