Modularize the worker code