More refactoring of Popups.js