Fixed index bugs