Created the patch with refactored code as per the description.