refactor sieve() to be smaller, more readable