extracted runtime critical loop in get_AA_R to new subroutine; ref #2