Bug fix: do not operate on closed file.