Extract cut-and-pasted code into a common module

code-deduplication: abrummet
These two modules are exact duplicates of each other

Until we know one or the other is unused, this is the safest solution

code-deduplication: abrummet