Refactored code for readability