Made code more generic for A nonzero