inv fix, check for undefined after gcd