Refactor worker.js