Fixed dialog so that it closes when finished.