[PATCH 7/7] Condense some duplicated and overly wordy code in custom.py.