Fix bug in caching