updated avgR.c