optimized getPrimes