defize the gen function. Not completed