This function seems really hacky to me. Maybe if we actually returned indices of the residues it would actually have the information it needed, without just guessing?