Check for gcd properly