Begin to code the generate function