Add unit test for flattening