more refactoring and javadoc