separate out popup menu handling for later reuse