rewrite as plugin