Code refactoring and modifications