Fix issue #618. Close and dispose filestreams after use.