Fix accounting of thread states.