put repeated code to set nat mode in a function.