Better error handling
Bug fix in caching code