added extra checking for when to show the modal