fixed indexing bugs