improved effeciency of isPrime(n) method