Fixed sorting in insertHelper