Refactor middleware to use instance variables instead of closure.

- This provides an easy access point for some attributes, and

- will help with some forthcoming features.