Added tallyCost function