Javadoc added, code cleanup and formatting