Implemented generate function