Fixed a bug where the key index was not updating properly.

Basically what was happening was multiple saves were occurring simutaneously
causing the keyindex to be overwritten.