More robust caching and cleanup