fix bug of inversing matrix