added code that check intersections