Bugfix: Close filese after reading

We had a pretty major resource leak in which we never close the files we open. This fixes that.