Completed code for matrix inversion functions