Rebuilt to a middleware handler, to implement other interesting stuff