MAINT: move more shared code into an existing helper function