refactor: hoist dedup helper