fixes to the middleware