Code refactoring to use the methods provided by @rbran100.  The refactoring turns out to work better than the itially code as it would have broken on the calendar terms, but works properly for them now, hooray.  #2013