fixes #19 ensure the input stream is closed