Cleaned up the streaming code.

This includes adding more tests, simplifying the code, and some PEP8 cleaning.