Fix bad-thread crash