minor refactor and better safeguards on term discounts, #15068