Some more improvements + test (on which it fails).