Fix some file closing issues.