flattening a multi linked list