Add java docs. Small refactoring.