Refactored code. Added showPopup function.