move some generation into a function.