Refactored popup show handler