Make sure not to reference inexistent element/scope

Just make sure that not existing element might be used. Note: this kind of smells, I know.

Reason: close might be called on popup directly (user clicks cross) or by the application. Anyhow, application does not know if popup still exists. This renders it a little more robust.