Bug fix to cost calculation