Fix file closing