Refactor common code to superclass
Fix when should pop up a dialog box