Improved javadoc and small refactoring