refactor as plugin