Some code cleanup, and more Javadoc.