adding Javadoc and doing some small refactoring