added rewriter and middleware