Multi-phase commit algorithm for streams, small refactoring