added javadoc and refactoring