Added JavaDoc and small refactoring