fixed for loop indexing