Implement matrix inversion