Fix file handle leaks

As mentioned in #5.

Would have created as a pull request but I don't think I can do that from within github's interface, so this'll do.