bubblesort with improvements