Add Javadoc

Javadoc added (+minor refactoring)