generation function modified, freet data according to task number