Fix bug in Total cost calculation