advanced insertion sort