optimized the all_primes() function