Add plugin system, refactoring