implemented thread exit