Added java doc and small refactoring.