Cleanup on deactivation

To avoid conflicting with my other pull requests, this branch was branched off of my enable_ie_support branch. Check the last commit for changes related to this pull request.
Also if this could be at the top of the wrapping function's scope so we don't have to hunt down the code to find it.