Made halting use mutexes, so that the thread stops processing.