Added function to invert a matrix