Added javadocs and refactoring.