improve gcd implementation