fixed indexing  bug