Reduce useless detach operations by making some non-const iterators cons...

...t.
Relevant to #422.