reduce and scan