residual looks good. think a bug lies in generation of A or structure of A