Refactored code to be readable