fixed indexing example to use better loop style