Fix setMode crash, and add test.