Added JavaDocs and refactored code.