Miguel/plugin refactor

I tried doing this and got pretty far, but there are some unsolved issues I still need to work through.  I will work on changing this up in a separate PR.