refactor looping image indices