Working on refactoring thread code.