Update dependencies, refactor middleware a bit