pre-delete function