Better caching logic