Refactored worker.cpp