Close GH-41: more sophisticated lookup for main.