Refactored code for better clarity