Moved upfront caching to before database query