fix some auto-flattring bugs