Refactored merge of sorted lists and its usage