refactor and test stream