more simplification on the middleware code