terminates gracefully