factored out readStream. readStream was duplicated numerous times