fix sorting removal of last element