properly cleanup all threads on exit