Removing a redundant sort