Refactor caching