Integrate @mor1 patch to fix the mode selection

Not to merge yet, as I haven't tested it at all.