added java doc and some refactoring