Various refactors to simplify stream token handling.