Error in refactored code