add javadoc comments
tests and refactoring