More code cleanup and some javadoc added