refactor: move stream length calculation to a separate module