Code cleanup and more Javadoc