fix generate function