Refactoring the code using ports in the worker.