Added JavaDoc and some small refactorings