Merge messages - optimization

Adding new elements to the sortable list was done in a O(n^2) way. Now it is O(n).