fix indexing errors