Just tweaked the location of file closing