Refactoring, updated javadoc