Added optimization for insertion sort