fixed the flatten case