minor refactoring + added some javadoc