Clean up streams related code a bit