This was complicated enough that I agree it's good to have it in a separate helper function.