Fixing flatten problem