factor out the generation code so we can use most of it in two places