Factor out underscore-dedupe logic [#77843004]