Modify sort logic