minor changes to indexes, fix out of range issue