added a file closing when the generating is over