refactored the patchs and code