minor refactoring of insertion sort