Improved reduceCost()

Fixed #107
Fixed #106
Fixed #103