implemented generate function