Merge a couple of copy-and-pasted functions

No change in functionality.