Refactor slightly and clarify javadocs.