Bug fixes for caching