improved handling of termination signals