Plugin bugfix

More tests and fixes for the plugin logic based off of @schneems' work.