moves thread_exit outside of the if block