some refactoring and javadoc