Update to code for error catching and to prevent collections from being deleted if they have content