isPrime function modified - more efficient code