Refactoring: extract stream parser