Added thread_yield instead of using raise() everywhere