moved the reduce code in 3d to the common code