fixed middlewares to actually output a function