Refactored code for better readability