update cost function