modify terminate_and_wait