Add BeforeDetach event