add a cost function