improved bubble sort implementation