Refactor sort row code moving