refactored code patch