Repository::ensureIndexes implementation and some fixes