updated code to account for intersections. Some edge cases can cause an infinite loop of looking to eradicate the intersections