fix bug with generate function