Insertion sort kind of algorithm implemented