Fixed isPrime method