updated isPrime implementation to a more efficient one