Added a bunch of javadoc, cleaned up some code