Added javadoc documentation and refactored methods

Updated the comments in the java files to proper javadoc standards and added in-line comments to describe what the methods were doing. Also refactored some methods that were slightly messy.