adding logic to stream handling,
since poll returns too soon on short-lived processes