Minor refactoring and javadoc'ing.