Losing modality in layered modal dialogs

Losing modality in layered modal dialogs

When I open a modal dialog A from my page, and then open and close a modal dialog B from dialog A twice, after closing B the second time, dialog A is no longer modal.

In the close-function of both dialogs I use the following code:
  1. dialogB.dialog("destroy");
  2. dialogB.remove();
Destroying en removing seems to be the safest route. Is there an alternative?

I really like JQuery UI and their Dialog, but when dialogs are no longer modal, they mess up my entire application.