Refactor some classes, add javadocs.