Consolidate stream processing logic in stream.py

Change-Id: I98ee2863c98f621627b1afb066cbd32fb0d5b7e9