Fix a bug with middlewares