Ensure file handles are always closed

This commit is advised by Andrew Boot(@bootany)
Merge pull request #11 from doloopwhile/ensure-file-handles-are-always-closed

Ensure file handles are always closed