Rewrote `insert' using iterators for simplification.