some refactoring and some javadocs comments