refactoring background script