Fixed a bug where the file wasn't getting closed