use index instead of each