Fix a bug where we'd insert into system.indexes twice, fix some tests
and add another.