Fixed rather silly bug in thread_delete