Formatted code and added javadocs.