Fix removal of the last thread from the thread list