bug fix: reading input stream twice