caching logic improved