refactored stream input read for driver.c