started refactoring popup.js