Refactoring worker script