I see four copies of this fix... is it possible to centralize this pair of lines into a shared function?  (The last of the four occurrences isn't quite paired up as cleanly but I bet we could still get it to share code with the others, given that the `else` case above it _is_ a dupe of the other line in the pair...)