added generate function, separated definitions