refactored popup window handling in app delegate