fixing indexing bugs