Simplify context object
Fix a middleware selection bug