added shutdown thread function