added error checks in worker.js