Refactor caching a bit