refactoring popup.js