Refactored code and Javadocs.