some optimizations and refactoring in plugins