_splitByDist function optimized from O(n^2) to O(n^2/2), time from ~1455 to ~1004