made gen_data more efficient