refactoring image iterator