Minor restructuring, plus added javadoc.