closing dialog was in the wrong place