Refactored code is working