restructure code + make as a plugin