Added own gcd function in case gmpy is not available.