Modified bubble sort