Remap user/item indexes correctly when sorting (#538)