Small sidenote, $window($active) is the same as $active (as the latter always returns the name of an existing window (or $null, although that wouldn't happen in popups)).