fixed index bugs.