gcd added, isPrime corrected