Tweaking sort logic