changed placement of index to be outside while loop