Better gcd (with completion) copied and fixed from dougborg