Middleware

I promise to use make from now on...

This is a fix for the tests from the last PR and it adds a middlewares array which can be looped over.