Fix cost function.