universal worker function