Move thread related functions to new file.