Some refactoring and more javadocs