Refactoring and added javadoc to several classes.