Fix some index bugs