Fixed several indexing errors