Small clean-up.  Factor-out common code for add, contains, and discard function pairs.