Refactoring of the addto_lists function

Removed some code duplications in tests and added refactoring of the addto_lists function,
namely removed ClientPair sorting and substituted by a maximum distance search in the list.