fixed logic so view controller is dismissed correctly.