initial code for generate function