Fix middleware ordering