Insertion sort: cleaner implementation and tests