Add properly IO handling on close.
Merge pull request #159 from opentechinstitute/master

Add properly IO handling on close.