fixed flatten issue