some more work on flattening