performance improvements to is_prime()