Refactoring and code cleanup
Refactoring