Cleanup leaking memory and filehandles
Merge pull request #179 from moshekaplan/patch-7

Cleanup leaking memory and filehandles