Implemented simple and dirty flattening