Add tests for scanning/iterating through streams, and fix bug related to
scanning.