Added callbacks for onOpen and onClose