refactoring code structure of plugin