More index tests, code cleanup.
Code cleanup, stats tests.