Correct a bug.
Factorize neighbor resolution code.