add cost calculation function