added overlap detection for n rectangles