Call close function when scope is destroyed