Rewrite gcd. Make pow global function