Ensure all open file handles and streams are properly closed

Hopefully fixes issue #118.  Let me know.