finished refactoring content script code