protection against calling file.close() twice. closes #2