changed one last for loop to a generate_n