Revised code for matrix, inverse and solve