Moved the thread function to utilities.