add before disconnect hook