Changed cost algorithm.