Updated the loop that checks for instances that have been removed from the document.