Patch enchant algorithm