Added javadoc comments and refactored.