make iterators immutable, plus some performance improvements