Generalized _get_residue_data() to arbitrarily large n