Fixed a bug with modals where an exception would be thrown if the modal was closed while loading