refactor usage of streams