Fix some issues with computing cost.