Implementation of insertion sort