fix indexing bug