Close files to prevent resource leaks
Merge pull request #21 from epeisach/master

Ensure that open files are closed to prevent resource leaks
adding a few assertNotNull checks