Fixed up a bunch of issues with the plug in / unplug code.