finished binary reduce implementation