Cleaning up patching logic

Fixing unpatching not working
Adding unpatch on plugin end.