fixed index issue and changed i to index