Original code looks fine to me.
Note that a constrain_file will stop the clearing to the parent.