Added a lot of javadoc and small code cleanups