Added callback function on open and close