Fixed a bunch of problems with rectangles and resizing the window, as well as adding some more unit tests etc.