restructure the code for plugin framework