Refactor the plugin manager