still working on flattening