slightly modified worker function