correct processing of end of input stream