fixing indexing errors