fixed indexing errors