Lots of little fixes after running some manual tests.
Added some comments.
Moved some classes around.