added flatten mode and example