improved popup handling