Updated the cost calculation