As the change currently stands I'm not a huge fan of extracting this function. It makes the diff pretty hard to read.
On the other hand, if adding `set` tests shows that the code needs to be more complex, it might tip the balance more strongly toward having a separate function.