Fix exception that occurs when deleting widgets.