a bit more flexible bubble sort