prepare() is rewritten to operate more simply; the state of the container is always consistent even between internal operations.