refactor nearestsourcepoint and nearersouce