Refactor to remove a bit of duplication. No functionality change.