Complete rewrite of plugin system