Added matrix inversion function