changed iterators to constant functions where possible