rewrite routing/middleware: all tests passing