Adding onBeofreClose callback