Adjusted to properly support window close and avoid mutation of collection while enumerating