Popup and other refactoring