generate() function working