More tests, refactoring, and javadoc.