Clean up dangling references at various points as necessary to eliminate reference leaks