refactor gcd