Fixed issue when trying to dismiss viewcontroller before it was being presented

There was an issue with a viewcontroller being dismissed before it had started to present. Improved this fix.