re ordered to get gcd working correctly