move code to plugin handler