Move next function to plugin register callback