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.
Is it worth just doing this by default? In other words, is there a scenario where there ISN'T fewer children where this still might need to be updated?