Added check before dismissing

Otherwise the VC may dismiss itself.