fixed indexing bug