add cost function part.