Add plugin context, some refactoring