Refactor patcher code