Fix index ordering issue in reduction