Merge pull request #530 from krabaey/feature-close-files

Close file streams to avoid fd leakage