Moved code from popup js into background js