Move sorting utility code to a separate package.