Check if the modal instance can be found

Added a check if the modal instance can be found.