Changed loop nesting in flush