Fixing bug in partition: swapping in the end