renumber residues functions