refactored popup.js