This is a destructive sort - returning a sorted array - why not throw the rest of the code into a new method to clean up the code just a bit more.