Fixed logic for caching, still not working