Split logic for getting the next document into its own function