Refactored code to make more readable