Implements insertion sort