NyroModal doesn't close correctly-Collection of common programming errors

Here’s sample a code.

$(".remove.group").live("click", function (ev) {
    var button = $(ev.currentTarget);
    var action = button.get(0).dataset["action"];
    var method = button.get(0).dataset["method"];
    var modal = $("#remove");
    modal.find(".primaryaction").bind("click", function (e) {
        $.ajax({
            url: action,
            type: method,
            dataType: "xml",
            success: function (rawResponse, status, xhr) {
               //some business logic
                $.nmTop().close();
            },
            error: function (xhr) {
                console.log(arguments);

                var message = "Could not remove group";
                alert(message);
                $.nmTop().close();
            }
        });
    });
    modal.find(".cancelButton").bind("click", function (e) {
        $.nmTop().close();
    });
    $.nmManual("#remove");

    return false;
});

I am using nyroModal and jQuery here.

All the click events work fine for the first time. But if I do reopen the modal again and click on either of the buttons nyroModal ends up throwing error:

this.elts.cont is undefined