Fix index bugs