small refactoring and added javadocs