extracted is_prime? method