added gracefull thread teardown