fixed flatten method