Refactored code based on feedback