subtle optimizations to use more iterators