cleanup some code, add some javadoc