Improved merge-sort implementation for lists