The Lady Vanishes

Catherine Lacy, Margaret Lockwood and Michael Redgrave in The Lady Vanishes
English tourist Iris Henderson (Margaret Lockwood) arrives at the "Gasthof Petrus" inn in the country of Bandrika, "one of Europe's few undiscovered corners". Iris is returning to Britain to marry a "blue-blooded cheque chaser", but an avalanche has blocked the railway line. The stranded passengers are forced to stay the night at the inn, including Charters and Caldicott, cricket enthusiasts who want to return to England to see the last days of the Test match.
That evening, Iris complains about loud folk music coming from the room above her. She has the guilty musician, Gilbert Redman (Michael Redgrave), thrown out of his room, only to have him move into hers, forcing her to capitulate.
Miss Froy (Dame May Whitty), a former governess and music teacher, listens to a tune performed by a folk singer under her window. Unseen by her, the singer is killed.
The next morning, before catching the train, Iris is hit on the head by a planter apparently aimed at Miss Froy, who then helps Iris onto the train. Also on board are Charters and Caldicott, Gilbert, a lawyer named Todhunter and his mistress "Mrs. Todhunter". As a result of her injury, Iris blacks out. After the train is moving, Iris wakes up in a compartment with Miss Froy and several strangers. She joins Miss Froy in the dining car for tea. Unable to be heard above the train noise, the elderly lady writes her name on the window with her finger. Soon after, they return to their compartment, where Iris falls asleep.
When Iris awakens, Miss Froy has vanished. The strangers in her compartment say they know nothing about an English lady. Even Todhunter in the next compartment, who spoke with Miss Froy earlier, pretends not to remember her. Iris searches, but cannot find her. She meets up with Gilbert, who agrees to help. Dr. Hartz (Paul Lukas), a brain surgeon, says Iris may be suffering from concussion-related hallucinations. Charters and Caldicott also claim not to remember Miss Froy, because they are afraid a delay would make them miss the cricket match.
Another lady appears, dressed exactly like Miss Froy, but Iris and Gilbert continue to search. They are attacked by a knife-wielding magician, Signor Doppo. They start to suspect that Dr. Hartz's patient, whose face is covered by bandages, is Miss Froy. Dr. Hartz tells his fellow conspirator, a British woman dressed as a nun, to drug Iris and Gilbert. Then, convinced they will soon be asleep, Hartz admits to them that he is involved in the conspiracy. The false nun does not follow Hartz's instructions out of loyalty to her fellow countrywoman; Gilbert and Iris escape, free Miss Froy and replace her with one of the conspirators.
When the train stops near the border, Dr. Hartz discovers the switch. He has part of the train diverted onto a branch line, where soldiers await. Gilbert and Iris inform their fellow passengers of what is happening. The train pulls to a stop and a uniformed soldier requests that they all accompany him. They knock him out and take his gun. Another soldier fires, wounding Charters in the hand, and a shootout begins.
During the gunfight, Miss Froy reveals to Gilbert and Iris that she is a British agent who must deliver a message to the Foreign Office in Whitehall. The message is encoded in the tune that the folk singer sang. Gilbert memorises the tune. With his help, Miss Froy slips away into the forest. Todhunter attempts to surrender, waving a white handkerchief, and is shot dead. Gilbert and Caldicott then commandeer the locomotive, and the group escapes across the border.
In London, Charters and Caldicott discover the Test Match has been abandoned. Iris jumps into a cab with Gilbert in order to avoid her fiancÃ©, and Gilbert kisses her. They arrive at the Foreign Office, but Gilbert is unable to remember the vital tune. Then he hears the melody on the piano; they are joyfully reunited with Miss Froy.

Question: Who discovers the switch?
Answer: Dr. Hartz