Middleware updated as per Chris notes