modified readfile to separate file handing from stream processing