changed index logic