Clean up the management of open files.

Specifically:

* Rather than opening the source file twice, seek.
* Use defer where possible.
* Document clearly why one of the calls to Close needs to not be
  deferred.