an attempt to fix flattop. Not sure it's right, but it's a first draft. Feedback is very welcome.