Here and below you might want to cleanup the dangling references, e.g., `cache[name] = undefined;` or `delete cache[name];` (not sure how that works inside `for`).