I _think_ you could sort the parts in place (being more careful than I was to defend against bad values). I'd try it myself but my VM's playing up - will see if I can grab a few minutes in the morning to give it a go.