improve handling of close window