This commit is move-only and doesn't make any functional changes. It
simply moves code around within ProcessImport() in preparation for
refactors in the next commits.
This is a partial backport of Core PR14491 : https://github.com/bitcoin/bitcoin/pull/14491/commits/a1b25e12a5f57048a4639964d57c0b46eb84cd4e
Some loop variable names have been changed to make sure we don't have shaddowing going on.