Documentation and bug fixes

Added a bunch of documentation and fixed a lot of bugs.
It's late, so I'm not going to be any more specific than that.