Tidied up pop-up code.