I looked quickly trying to see how the existing code was changed, which seems to be mainly moved in a dedicated function. I didn't dig in the new algorithm (mode), being specific for the feature wanted with this PR.
Maybe @juha-h wants to check a bit and see if the old mode (now STANDARD) is not affected somehow.
Otherwise, if nobody else has comments, I am fine to merge.