Refactoring and better handling of errors in plugins.