added/updated javadocs. Refactored some code