fix indexing bugs