Moved patching and unpatching code to the appropriate classes