Fixed bug in rectangles, removed lots of unwanted globals.