Fixed Patching code. thx aaron.
Seem to have fixed the TagRef and Duplicate tag error.