Added some subtle changes to the middleware.