Restructure format, add group and flatten
Add test cases for format