Middleware precedence fix