fixed bugs in reduction functions