added onClose function and fixed a bug in success callback