Fix bug in setting custom_ref_applied flag