add events onOpen and onClose