Reworked and improved popup functionality