Large refactorization to merge lists from hosts

A large refactorization is performed to support merging lists from
multiple hosts. It is really painful and the code becomes really ugly.