Fix middleware

Addressed problem with the middleware.