Sorry for just now realizing, but the Cancel button is already handled by default, so this is not necessary at all. This line of code should be removed.