Made logic for deleting resources less error prone.