finished addition of generate function