Fixes for index handling.

* Fix so that if an update results in fewer indexed children, extra
indices will be removed.
* Add a hook to allow modified handling of index values, since the
default handling isn't appropriate for all cases.
* Includes tests.
100% actually, I think that's how this slipped through -- when there are least as many new entries, they basically overwrite the old entries, so the problem was only happening when there weren't enough new entries to overwrite all the old ones.