Javadocs, and some minor refactoring.