Separated algorithm to two kernels, added segmented reduce