preparing the middleware