Connection, Stream: performance optimizations. Fixes #47