shutdown background threads cleanly