Converted two reduces to single forEach for more efficient processing