Fix ordering of middleware