Use a block to automatically close file.

Should close #1201