Refactored code, making it easier to read