updated primes calculation to be more efficient