fixed and optimized Bubble sort