fix caching logic