Refactoring and plugin handling fix