implemented Max Rectangles. big work on refactor