Refactor to avoid caching ivars across requests

Rack middleware only get initialized once and then called multiple times. We shouldn't be storing request specific objects in ivars.