fixed issue where not closing ifstreams/ofstreams