Refactoring and adding Javadoc