added java doc to new class
some refactoring
fixed bugs and conform to API