Simplify algorithm. No changes to sort behavior or runtime.