Add active selection support to PluginManager

Refine error handling, make the code more readable.