Minor refactoring and adding javadoc