> Should I put in another issue/PR to refactor this code to remove duplication?

That would be awesome, but let's first merge the two that you currently
have opened.