Code cleanup and Javadoc