Fix bug in the thread worker implementation