Refactored code