Added support for varying output cache by authentication state. More cleanup and refactoring.