As a bonus the patch untangles a bit the logic and makes the code easier to grasp. PR: 192108 MFC after: 1 week