Making the middleware a little more modular so it can be easily
subclassed