More changes to support middlewares