Add optimizations for stream operations