minor refactoring and adding some javadoc