Second refactor to algorithm; now ot uses Stream