update costfunction