Add primes() function and minor improvements