fix flatten iterator