Attempt to fix the thread code