optimized bubble sort