Added safety check for if UIViewController is being presented when trying to dismiss