made some minor modifications related to case when A->r==0