Moved flatten and dematerialize inside stream
Minor stylistic fixes
Move more functions into Stream with TypeEquality
Merge pull request #1384