Fix some bugs in reduce