Changed the way the running status of the thread is checked.