# Defined row operations for making a matrix ,containing varibel coefficients, into RREF

I am trying to solve for the inverse for a given $$3x3$$ matrix. The matrix looks like this: $$\begin{pmatrix}1&0&1\\ \:a&0&1\\ \:1&a&0\end{pmatrix}$$ I have tried solving it through carrying out row operations on the matrix above whilest in parallel carrying out the same operations on a $$3x3$$ Identity matrix. I am worried that I might be preforming "undefined" or "non-approved" row operations on $$A$$ and that it, is the cause of the incorrect result. What i got so far looks like this:

$$\begin{pmatrix}1&0&1\\ \:\:\:\:\:a&0&1\\ \:\:\:\:\:1&a&0\end{pmatrix}$$ $$R_2\to R_2 -aR_1$$

$$R_3\to R_3-R_1$$ $$\begin{pmatrix}1&0&1\\ \:\:\:\:\:\:0&0&1-a\\ \:\:\:\:\:\:0&a&-1\end{pmatrix}$$

Assuming $$a\neq 1$$

Switch $$R_2\leftrightarrow R_3$$

$$\begin{pmatrix}1&0&1\\ \:\:\:\:\:0&a&-1\\ \:\:\:\:\:0&0&1-a\end{pmatrix}$$

$$R_3\to \frac{1}{1-a}R_3$$$$\begin{pmatrix}1&0&1\\ \:\:\:\:\:\:0&a&-1\\ \:\:\:\:\:\:0&0&1\end{pmatrix}$$

$$R_2\to R_2+R_3$$

$$R_1\to R_1-R_3$$

$$\begin{pmatrix}1&0&0\\ \:\:\:\:\:\:\:0&a&0\\ \:\:\:\:\:\:\:0&0&1\end{pmatrix}$$ $$R_2\to R_2\cdot(1/a)$$ $$\begin{pmatrix}1&0&0\\ \:\:\:\:\:\:\:0&1&0\\ \:\:\:\:\:\:\:0&0&1\end{pmatrix}$$

This it what i am getting, if i do the same elementry row operations in the same sequence to the Identity matrix i get an incorrect result. What am i doing wrong? (Sorry about the messy notation, first time poster) Kind regards and many thanks!

$$a≠0,1$$ or the matrix will be singular. The row transformations look okay. The inverse comes out to be $$\begin{pmatrix}\frac1{1-a}&\frac1{a-1}&0\\ \:\frac1{a(a-1)}&\frac1{a(1-a)}&\frac1a\\ \:\frac a{a-1}&\frac1{1-a}&0\end{pmatrix}$$.