Fixed misc. errors, added some javadoc comments.

Fixed coding style errors, added a new function, cleaned up code in
general.