Some improvements to background.js