sharing the code for generalizing AR