refactor popupselector code